Tech Musings

Friday, April 07, 2006

PHP and file uploads

After a few hours of dedicated research, I finally figured out how to increase the PHP file upload restriction on my OS X Server. I tried a plethora of suggestions from numerous discussion boards and Web sites to no avail, mostly because the people who were posting were not fighting with this limitation issue on Apple's ridiculous flavor of Apache running under WebObjects.

After tweaking the upload_max_filesize without a hitch, I absolutely couldn't for the life of me increase the post_max_size in the php.ini file to anything greather than 8M (8 MB). Finally, I actually MOVED the directive by cutting and pasting it further down in the php.ini file next to the upload_max_filesize line. And voila! it was suddenly recognized by my server!

I also added the following directives to the very end of my httpd.conf file:

LimitRequestBody 0
php_value upload_max_filesize 75M
php_value post_max_size 75M
php_value memory_limit 35M

You direct apache to set an unlimited amount on the HTTP request body message when the LimitRequestBody equals 0. I also increased the max_execution_time to 300 seconds and the max_input_time to 260 seconds in my php.ini file, and changed the KeepAlive and timeout adjustment figures in Server Settings.

Finally, I added a hidden field named MAX_FILE_SIZE with a value of 73400320 directly before the file upload field in my html form. This field will cut off the process if someone tries to upload a file greater than 70 MB to the teacher exchange. I wrote some PHP validation which redirects the user to a message page telling them the upload failed because their file exceeded the file upload restrictions set on my server.


Post a Comment

Links to this post:

Create a Link

<< Home