Home » Php » php – File Upload won't move from temporary location to destination

php – File Upload won't move from temporary location to destination

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am working on a PHP Script to upload a file. I’m working with Xampp on MacOs. I checked the temporary location and it does exist there, but won’t be moved to the destination using move_upload_file function.

The form for the upload:

<form action ="upload.php" method ="POST" enctype="multipart/form-data">
<input type ="file" name="file">
<button type="submit" name="submit"> UPLOAD </button>

</form>

And the PHP:

<?php

if(isset($_POST['submit'])) {
  $file = $_FILES['file'];

  $fileName = $_FILES['file']['name'];
  $fileTmpName = $_FILES['file']['tmp_name'];
  $fileSize = $_FILES['file']['size'];
  $fileError = $_FILES['file']['error'];
  $fileType = $_FILES['file']['type'];

  $fileExt = explode('.', $fileName);
  $fileActualExt = strtolower(end($fileExt));

  $allowed = array('jpg', 'jpeg', 'png' , 'gif');
  if (in_array($fileActualExt, $allowed)) {
      if ($fileError === 0) {
        if ($fileSize < 50000000 ) {
            $fileNameNew = uniqid('', true).".".$fileActualExt;

            $fileDestination = 'uploads/' .$fileNameNew;
            $des ="nfs://192.168.64.2/opt/lampp/temp";
            move_uploaded_file($fileTmpName,$des.$fileDestination);
            header("Location: uploadphoto.php?uplpadsuccess");


        } else {
            echo "Your file is too big!";
        }

      } else {
        echo "There was an error uploading your file";
      }
  } else {
      echo "You cannot upload files of this type";
  }


}

After reading some things online, I added the path to the destination of the temporary files. Now with the IP Adress- before only as /opt/lampp/temp.
I do get a success message but the file is nowhere to be found in the uploads folder. How could I possibly fix this?

How to&Answers: