PDA

View Full Version : PHP File Upload issues... Server Prob?



singedpiper
01-04-2006, 11:29 PM
I am attempting to use portablewebap to write an interface for a laptop based picture frame... the following code was supposed to upload an image... however, I'm getting the error:





Warning: move_uploaded_file(PHP\uploadtemp\phpAF3.tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\Documents and Settings\Charlie\Desktop\no hassle php\PortableWebAp3.1\PortableWebAp3.1\Program\www\localhost\music\upload.php on line 103

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'PHP\uploadtemp\phpAF3.tmp' to 'files/test2.txt' in C:\Documents and Settings\Charlie\Desktop\no hassle php\PortableWebAp3.1\PortableWebAp3.1\Program\www\localhost\music\upload.php on line 103
error moving file from PHP\uploadtemp\phpAF3.tmp to files/test2.txt




here's the pertinant code:




$uploadDir = "files/";
$i = 1;
$temp = $uploadDir;
$simplename = basename( $_FILES['file']['name']);
while(file_exists($uploadDir.$simplename))
{
$uploadDir = $temp.$i;
$i++;
}
$uploadFile = $uploadDir.$simplename;

if(is_uploaded_file($_FILES['file']['tmp_name']))
{
}
else
{
echo "the file was not uploaded correctly, try again";
exit(0);
}

if(move_uploaded_file($_FILES["file"]["tmp_name"], $uploadFile))
echo "sucessful upload to $uploadFile";
else
{
echo "error moving file from ".$_FILES["file"]["tmp_name"]." to $uploadFile";
exit(0);
}




Is the error with my code, or the server? help? :confused:

thesavior
01-04-2006, 11:43 PM
one thing i notice is that you are trying to move a file into a text document, you can't do that, but you CAN move it to a folder.

singedpiper
01-04-2006, 11:50 PM
isn't move_uploaded_file supposed to move and rename in one step? I was under the impression that it moved the binary contents of the file to the filename specified

thesavior
01-04-2006, 11:58 PM
that is incorrect.


move_uploaded_file ( string filename, string destination )


try using this code, and tell me what happens:


$uploadDir = "files/";
$i = 1;
$temp = $uploadDir;
$simplename = basename( $_FILES['file']['name']);
while(file_exists($uploadDir.$simplename))
{
$uploadDir = $temp.$i;
$i++;
}
$uploadFile = $uploadDir.$simplename;

if(is_uploaded_file($_FILES['file']['tmp_name']))
{
}
else
{
echo "the file was not uploaded correctly, try again";
exit(0);
}

if(move_uploaded_file($_FILES["file"]["tmp_name"], $uploadDir ))
echo "sucessful upload to $uploadDir";
else
{
echo "error moving file from ".$_FILES["file"]["tmp_name"]." to $uploadDir";
exit(0);
}

singedpiper
01-05-2006, 12:54 AM
i believe now that my issue was mislableing my file directory.. the code you provided creates a file called files with no extension in the server root... you do need to specify file name and extension... just in an existing folder