Hey guys, first post here! Thought I'd make it a whopper.
So here is the deal, I have to write a file upload script to plunk into an existing page. The upload is a strait PHP/POST upload. I have one file that handles all the forms, the action just goes to php_self and I sort through it there.
There are basically two forms, then a results page. My one upload.php file handles all three.
The user fills in data for the first form, name, company, how many files they need to upload, etc... When submitted, it goes around to form number 2. This form is dynamically created to give them the number of file input boxes they need. It's a barbaric way to do things, but I'm not being paid much. So...
They browse for the files they need and submit. I create a folder on the server based on their input from the first form, and upload the files there. This all works great. I have a file size filter, a file type filter, and other stuff. But the problem is with PHP's server side file size limitations. That is max post size and max file size.
When the user betrays my client-side file size check, I just show the error and it's good. But when the file is too big for php.ini settings, I cannot for the life of me trap this error. What happens is the page just refreshes, which takes me back to the first form page, not the results page that is supposed to be shown.
I have tried trapping the error in the upload code here:
if (move_uploaded_file($file_tmp,$dir.$file_name)) {
echo "<script>alert('success')</script>";
echo "File $i: ($file_name) Uploaded.<br>";
} else {
die("The file is bigger than this server allows");
}
Never mind the echo, that's just troubleshooting. Also, the code right here has changed about 10 times, I've been putting in every kind of error trap that google will throw at me. The problem is, when the file they input exceeds what PHP allows, the code never seems to get here. It's as if all the file checking never takes place, the page just refreshes back.
I've tried setting my own error handler function, it won't run. I've tried putting DIE statements and javascript popups all through the code to see if even reaches those areas, and it doesn't seem to. After they hit submit, the page loads, and that's it, it just loads, then it goes back to the first form, no errors, no warnings.
Also, when it refreshes back to the first form, there is no post data. I've dumped the $_POST data and it is empty after it does this. However if I hit refresh on the page, it tells me that it has to resubmit data! I don't know what data, since POST is empty!
It is getting aggravating. How can I trap this dumb error? How can I even trouble shoot? It leaves no trails or clues! I've been reading the php manuals, W3C, reading up on file uploads. People tell you how to increase file size limitations in php.ini, they don't tell you how to trap the errors.
So I guess the basic question is I'm wondering how the logic goes from file upload to max file size and max post size. When you try to submit a form with a file that exceeds server limits, what is SUPPOSED to happen? How would somebody normally trap this condition? I know for a fact I have no code to just refresh the page on an error, no code to go back to the first form on error, it is a mystery. So how do I trap the error?
Thanks!