lundi 26 septembre 2016

move_uploaded_file() not throwing any error, but still not working

This code is not throwing any error. But still the file is not getting uploaded in the respective folder. NO ERROR is thrown!

  <form action = "" method = "POST" enctype = "multipart/form-data">
     <input type = "file" name = "image" />
     <input type = "submit"/>

     <ul>
        <li>Sent file: <?php echo $_FILES['image']['name'];  ?>
        <li>File size: <?php echo $_FILES['image']['size'];  ?>
        <li>File type: <?php echo $_FILES['image']['type'] ?>
     </ul>

  </form>

PHP

<?php
   if(isset($_FILES['image'])){
      $errors= array();
      $file_name = $_FILES['image']['name'];
      $file_size = $_FILES['image']['size'];
      $file_tmp = $_FILES['image']['tmp_name'];
      $file_type = $_FILES['image']['type'];
      $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));

      $expensions= array("jpeg","jpg","png"); //For these formats

      if(in_array($file_ext,$expensions)=== false){
         $errors[]="extension not allowed, please choose a JPEG or PNG file.";
      }

      if($file_size > 2097152) {
         $errors[]='File size must be excately 2 MB';
      }

      if(empty($errors)==true) {          /*This part is not working it seems*/
         move_uploaded_file($file_tmp,"D:\Data\web\ResearchAdvancement\students\Sarang\New\S\uploads\\".$file_name);  //Where I wish to upload.
         echo "Success";
      }else{
         print_r($errors);         //No errors are thrown
      }
   }
?>

Trying to upload image files to a respective folder. The above code doesn't contain any error, however the file is not getting uploaded. Please help!




Aucun commentaire:

Enregistrer un commentaire