Forum Moderators: coopster

Message Too Old, No Replies

Uploading files problem

         

DFrag

1:39 am on Mar 5, 2004 (gmt 0)

10+ Year Member



Hello all,

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?

ahmed

7:35 am on Mar 5, 2004 (gmt 0)

10+ Year Member



$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;

DFrag

10:41 pm on Mar 7, 2004 (gmt 0)

10+ Year Member



Damn... thanks for picking that up.

However, I tried the changes and still getting the same error?

DFrag

10:00 pm on Mar 10, 2004 (gmt 0)

10+ Year Member



anyone?

Birdman

10:20 pm on Mar 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have the MAX_FILE_SIZE hidden input in your form? That may have something to do with it.

<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.

More on handling file uploads [php.net]