Having problems saving an uploaded file.

I just tried to create a form using xhtml to upload a file. The code I used in the php file is this one:

<?php if( ( ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") ) && ($_FILES["file"]["size"] < 20000) ) { if( $_FILES["file"]["error"] > 0 ) echo "Return Code: " . $_FILES["file"]["error"] . "
"; else { echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . $_FILES["file"]["size"] . "
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; if( file_exists("upload/" . $_FILES["file"]["name"]) ) { echo $_FILES["file"]["name"] . " already exists."; } else { move_uploaded_file( $_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"] ); echo "Stored in: " . "upload/" . $_FILES["file"]["name"] . "
"; } } } else { echo "Invalid file"; } if( file_exists("upload/" . $_FILES["file"]["name"]) ) echo "The file was transferred successfully."; else echo "ERROR: The file was not transferred."; ?>

What the explorer shows is this:

Upload: web-browsers.jpg
Type: image/jpeg
Size: 14239
Temp file: C:\Windows\Temp\php30FA.tmp
Stored in: upload/web-browsers.jpg
ERROR: The file was not transferred.

I’m following a tutorial, so even though I’m using this
move_uploaded_file( $_FILES[“file”][“tmp_name”], “upload/” . $_FILES[“file”][“name”] );
I don’t know where the file is going to be saved.
I setup apache to work just in my computer so this is the address I use to access the form:
http://localhost/php/upload_file_form.xhtml
Since the php file is in the same folder, is the uploaded file going to be saved in localhost/php/upload/ ??
I don’t understand why the file is not being uploaded :S
I also tried to search for the temp file but the one shown using "$_FILES[“file”][“tmp_name”] " doesn’t exist.

Please help!

I appreciate your time

Check if user has permission on folder “upload/”.

Tmp files will be erased, posibly after script executation.

Sponsor our Newsletter | Privacy Policy | Terms of Service