Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uploading files

Status
Not open for further replies.

MacTommy

Programmer
Feb 26, 2007
116
NL
This is a newbie question I guess. I've got a script that should let users upload files, but nothing seems to happen.

The form looks like this:
Code:
   <form enctype="multipart/form-data" action="./myPage.php"
	  method="POST">
     <input type="hidden" name="MAX_FILE_SIZE" value="10000000">
    Upload a new file: <input name="sUploadFile" type=file><br>
    <input type="submit" value="Upload File">
   </form>
After that I print $_FILES['sUploadFile']['tmp_name'] which is something like /var/tmp/phpNsBgs0. However, in /var/tmp/ there are no files called like that..?!?
file_uploads is on in my php.ini. The max size is 2Mb.
Also, I tried setting upload_tmp_dir to another folder in my php.ini.
This results in the $_FILES['sUploadFile']['tmp_name'] still being /var/tmp/phpNsBgs0, while move_uploaded_file() starts to complain that it can't find a file in my newly set upload_tmp_dir.

I'm quit at loss..?!?
 
Oops, that last bit is actually not true. setting upload_tmp_dir appears to have no effect at all..?!?
The $_FILES['sUploadFile']['tmp_name'] is still set to something in /var/tmp/ while there is nothing there...
So move_uploaded_files() can't find it and complains about that...
 
the temp files created by php are automatically deleted once the script is finished.
so you have to do the move_uploaded_file() before the receiving script ends.
remember to check the $_FILES['sUploadFile']['error'] before you start processing. that returns lots of useful information about whether the file has uploaded properly and, if not, what the problem might be.

 
Check PHP.ini to find out where your temp_dir is supposed to be. You need to also make sure that user as which PHP is running has access to that folder.

You may also want to echo $_FILES['userfile']['error'] It should have some value if there was some kind of problem uploading the file.

If there's a value there other than 0, it means there was an error.

PHP's online manual provides a list of the error codes, so you can tell what went wrong:



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks guys!
I found out about the $_FILES['myFile']['error'] already but it didn't give one (an error, that is...).
Probably because everything is fine. I just have to do something with the file before the script ends as jpadie says.
That might be it because I have several scripts that work togther via AJAX.
Anyway, thanks a lot for the suggestions.
Cheers!
 
Technically $_FILES['sUploadFile']['error'] would have a Number, that corresponds to an error or 0 if there is no error not really an error message.

We'd need to know ab bit more about your script to see how its working.







----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top