Forum Moderators: coopster
I'm trying to upload images to my server but I am getting the following message:
Warning: move_uploaded_file(*filepath*): failed to open stream: No such file or directory in *file* on line 43
Warning: move_uploaded_file(): Unable to move 'c:\temp\phpDB6F.tmp' to '/data/gallery/images.php/images/p1_hg.jpg' in *file* on line 43
The target directory has rw permissions.
Code is as follows:
Submit form:
<form action="images.php" method="post" enctype="multipart/form-data">
<input name="picture" type="file"><input name="submit" type="submit"></form>
Upload form:
$path = $_SERVER['PHP_SELF'];
$image_path = $path."/images";
if(is_uploaded_file($_FILES['picture']['tmp_name']))
{
move_uploaded_file($_FILES['picture']['tmp_name'], $image_path."/".$_FILES['picture']['name']);
}
Any ideas?
$path = $_SERVER['PHP_SELF'];
$image_path = $path."/images";
php_self gives you the path AND filename of the current document.
try this instead :
$path = dirname($_SERVER['PHP_SELF']);
also, I usually build the destination outside of the call to move_uploaded_file, that way I can do a quick echo to make sure it's correct :
$dest = $image_path."/".$_FILES['picture']['name'];
echo $dest;
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
From the manual:
<form enctype="multipart/form-data" action="_URL_" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
The "_URL_" in the above example should be replaced, and point to a PHP file. The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file input field, and its value is the maximum filesize accepted. Also, be sure your file upload form has enctype="multipart/form-data" otherwise the file upload will not work.