0

I'm very new to coding. I'm trying to upload an image (any file for now) in a particular folder.

<?php

$name = $_FILES["file"]["name"];
$tmpName = $_FILES["file"]["tmp_name"];

if(isset($name)){
    if(!empty($name)){
        $location = "uploads/";
        $destination_path = getcwd().DIRECTORY_SEPARATOR;

        if (move_uploaded_file($tmpName,$destination_path.$location.$name)) {
            echo "uploaded!";
        }
        else {
            echo "boo";
        }
    }
    else {
        echo "please choose a file";
    }
}

?>

<html>
<body>
   <form action="upload.php" method="POST" enctype="multipart/form-data">
    <input type="file" name="file">
    <br>
    <br>
    <input type="submit" value="SUBMIT">
    </form>
</body>
</html>

Everything is getting executed properly until the "move_uploaded_file" if-condition. Getting the else-echo-statement("boo")

sheldon15
  • 1
  • 2
  • 3
    Enable PHP error handling and echo $destination_path.$location.$name before moving and then any error from [move_uploaded_file](https://www.php.net/manual/en/function.move-uploaded-file.php) – mplungjan Sep 25 '19 at 05:34
  • unclear. do you want to make this upload without page refresh? or the file is not uploading due to some issue? – Sumit Wadhwa Sep 25 '19 at 05:35
  • @JayWadhwa That would likely be a later thing - let's get the file uploaded first – mplungjan Sep 25 '19 at 05:36
  • 1
    Possible duplicate of [move\_uploaded\_file gives "failed to open stream: Permission denied " error after all configurations I did](https://stackoverflow.com/questions/8103860/move-uploaded-file-gives-failed-to-open-stream-permission-denied-error-after) – digijay Sep 25 '19 at 05:38

0 Answers0