Page 1 of 1

File Upload Questions

Posted: Sun Sep 24, 2006 1:53 pm
by Toot4fun
I have a page that uses move_uploaded_file() to upload files. I'm having an issue with the ['size'] item, where if a large file is selected (~10MB), the page doesn't seem to return an error - either from PHP or my message. Is there a way for me to trap this?

Ideally, I'd like to be able to check the filesize before the file is uploaded. But everything that I've found says that this pretty much isn't possible unless you're using Windows boxes to host, in which case you may be able to use the FSO to calculate it. Anyone have any suggestions for someone like me with a hosting company that runs non-Windows boxes?

Posted: Sun Sep 24, 2006 1:59 pm
by feyd
I'm not sure I understand your first question, or more specifically the description leading to it.

As for getting the file size, it's not possible without external help. The file size is generally transmitted as part of the initial upload submission, but PHP doesn't give you that information until after the file has been uploaded. The external help I'm referring to is ActiveX, Java or Flash since those technologies can interact with a user's file system more readily than Javascript or PHP can.

Posted: Sun Sep 24, 2006 2:06 pm
by Toot4fun
Thanks for the clarification on obtaining the file size before uploading.

As for my original issue, here is some more information:


I have a page that allows users to enter keywords and a description for a file that they upload. I have imposed a 5MB limit (MAX_FILE_SIZE) for any file that is uploaded. If I choose a file that is, in this case, 10MB and submit the form, the page loads, and loads, and loads and eventually my original page is returned - no DB entry, no uploaded file and no error message.

To test that my code worked correctly, I set the MAX_FILE_SIZE to 10000 and tried to upload a 20K file. As expected, the page was returned with my error message indicating that the file was too large to upload. I haven't really done any incremental testing to know exactly where I lose the message, but the 10MB file definitely exhibits this behavior.

Posted: Sun Sep 24, 2006 2:37 pm
by feyd
Check to make sure the other settings associated with file uploading (all listed on PHP's feature page for uploads) are set correctly too. As a last resort, you may want to check your error logs as the error may be going there instead of your code.