Saturday 15 October 2016

file upload - basic move_uploaded_file warning from php.net



I took this basic upload file script from php.net and it is giving two warning before it move the image to the directory.




Warning:
move_uploaded_file(public_html/your/inventory_images/penguin.jpg)
[function.move-uploaded-file]: failed to open stream: No such file or
directory in /home3/ny/public_html/your/anotherformsale.php on line 73




Warning: move_uploaded_file() [function.move-uploaded-file]: Unable
to move '/var/tmp/phpnIxYMK' to
'public_html/your/inventory_images/penguin.jpg' in
/home3/ny/public_html/your/anotherformsale.php on line 73




I am getting this warning after I have tried to upload a image with a basic move_upload script below.



 
$uploaddir ='public_html/your/inventory_images/';//<----This is all I
changed $uploadfile = $uploaddir . basename($_FILES['file']['name']);

echo '
'; if (move_uploaded_file($_FILES['file']['tmp_name'],
$uploadfile)) {
echo "File is valid, and was successfully uploaded.\n"; } else {
echo "Possible file upload attack!\n"; }

echo 'Here is some more debugging info:'; print_r($_FILES);


print "
";
?>

Answer



According to warning message(No such file or directory in /home3/ny/public_html/your/anotherformsale.php on line 73) the path you are using is wrong.



it should be set to



$uploaddir ='/home3/ny/public_html/your/inventory_images/';



After confirmation of path you should also make sure the destination directory is writable.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...