0

I am new to php. I am getting below error after i uploaded a file. could you please tell me what went wrong in below code:

PHP Warning:  move_uploaded_file(): Unable to move '/tmp/phpgjqCAw' to 'uploads/mypic.png' in /var/www/html/uploader.php on line 7

uploader.html

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

uploader.php

<?php

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

?>
John
  • 281
  • 1
  • 4
  • 9
  • See [move_uploaded_file(): Unable to move](https://www.google.de/search?q=site:stackoverflow.com+PHP+Warning:+move_uploaded_file():+Unable+to+move) to narrow down your issue. There are dozens of causes. Problem guessing is off-topic. – mario Jun 05 '16 at 10:02
  • 1
    do you have rights to write in uploads ? ( chmod 777 uploads ) – Michał G Jun 05 '16 at 10:02
  • @MichałG After changed folder to 777, able to upload.. Tnq – John Jun 06 '16 at 06:03

0 Answers0