Jump to content

PHP file upload


djp1988

Recommended Posts

I have an image upload form on my site, I'm testing it on my localhost, for some images, when I submit the form, the request just never ends, and no file gets added to the specified directory.This wouldn't usually surprise me but the file I'm dealing with is actually only 98KB and is 600x400 pixels, I looked at my -max_execution_time-max_input_time-memory_limitIn php.ini and their values were 30, 60, 128MB respectively (i presume this is the default). So I doubled each value and on first attempt my upload worked, but what I can't understand is why did the upload "sometimes" work ? Maybe I need to use flush() to free up memory before my upload ?And some files seem to have an upload success rate higher then others, the latter only uploaded twice on at least 10 attempts.I'm posting the upload form to an iframe, and using javascript to show an ajax-type loader icon, there's nothing more frustrating then that never changing because the PHP script (which outputs a parent.upload_finished() javascript statement) never actually loads.I could use some pointers on uploads and memory with php, can anyone help ?

Link to comment
Share on other sites

How do you know that the PHP script does end but just doesn't output the Javascript code? Maybe it's displaying an error message instead. You should get uploads working before trying to do something like this. It would also be a good idea to turn on error logging and send all of the errors to a log if you're not able to see the output of the script yourself. Are you checking for Javascript errors in the browser also?

Link to comment
Share on other sites

Hi, yea I've looked in the logs and when I say the script doesn't stop, what I mean is the http request for that page is actually in a state of loading for over 5 minutes, well until i close that window actually. So it looks like the PHP ran out of memory and couldn't finish up and for some reason the http connection to that request stayed alive during this time.This and the mail() function are the two things I find unreliable in PHP...

Link to comment
Share on other sites

I've never seen a problem with file uploads just hanging. If Javascript is telling you that the request hasn't ended yet, then my suggestion is to get it working without Javascript before you add that in. Even so, if PHP quits but the request does not close, that's the web server's fault, not PHP.

Link to comment
Share on other sites

Are you checking the error log? If PHP is timing out or running out of memory it will report an error. All you've mentioned so far are symptoms, I'm looking for something specific. If PHP is having an error, it will put an error message in the log. If the web server is having an error, it will also use its error log to record it.

Link to comment
Share on other sites

Okay maybe I'm not logging to the correct file ? I specified an error log in my vhosts.conf file which does show apache errors, but maybe not php errors ? Although when I execute error_log() in PHP I do see output in the same log, I am checking that and it holds no clues

Link to comment
Share on other sites

You may need to turn on the error log in PHP instead of having it print errors on the page. This is how I do it:error_reporting(E_ALL);ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');ini_set('html_errors', 0);ini_set('log_errors', 1);You can remove the error_log setting if you want to continue writing to the same file, or else that will write errors to a file called error.log.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...