UPload problem $20 reward for the answer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
liquidkool
Forum Newbie
Posts: 9
Joined: Thu Feb 20, 2003 7:50 am

UPload problem $20 reward for the answer

Post by liquidkool »

Ok. I have an upload script that was only allowing me to upload files in the several hundred byte range even though the upload_max_filesize in php.ini is set at 2M.

So I moved all the files to a new server. Now I am limited to anything over 450KB. Again the value in php.ini is set at 2M.

Can anyone tell me what server configuration is causing this problem

it is almost like a tmp copy of the image isn't getting copied to the server with the larger images because I get an error:

Warning: getimagesize: Unable to open '' for reading. in /home/public_html/uploadimage.php on line 75

The same picture, same name, same dimensions brought into PhotoShop and saved with a lower quality rating will upload no problem.

When I:

print_r($_POST);
print_r($_FILES);

I Get:

( [MAX_FILE_SIZE] => 8000000 [Submit] => Submit Picture ) Array ( [myfile] => Array ( [name] => myfile3.jpg [type] => image/pjpeg [tmp_name] => /tmp/php8SdQOI [error] => 0 [size] => 436817 ) )

This is with a file that works. When I throw a file of size 835213 at it both arrays are empty.


OS is linux, apache server. Upload works fine wiht anything under 450KB so i dont see it as a coding issue as much as a server config issue. I just need to track down the culprit causing this.
liquidkool
Forum Newbie
Posts: 9
Joined: Thu Feb 20, 2003 7:50 am

Post by liquidkool »

I solved it myself.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

can i have $20 for reading it? lol
liquidkool
Forum Newbie
Posts: 9
Joined: Thu Feb 20, 2003 7:50 am

Post by liquidkool »

Well i haven't definately confirmed that i have solved the problem because i beleive it to lie in the php.conf file which i cannot access so i am talking with the webmaster to get a change made.

So stay tuned maybe you will have a shot at the $20 bucks :D
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Here are some things that might help (from the manual)
If you're on a shared host that won't allow you to modify the php.ini file and your max_upload_size is set low, you can create an .htaccess file in the upload handler script directory that contains:

php_value upload_max_filesize 8000000
Uploading huge files still remains a problem, even after you've set upload_max_size and post_max_size to reasonable sizes (in my case respectively the defaults 2M and 8M).

MAX_FILE_SIZE is often ignored and php doesn't cut in to stop the transfer, so if you're using Apache (i'll bet you are) try limiting transfers with LimitRequestBody.

Be advised that you don't set this directive too low, or Apache will return a document without data.
If you we dumb like me you installed Redhat 8.0 and kept the default install of packages for Apache 2.0 and PHP4.2.2. I could not upload any files larger than 512kB and all the php directorives were set to 32MB or higher.
memory_limit = 128M
post_max_size = 64M
upload_max_filesize = 32M

And my upload web page was set to 32MB as well:
<Form ID="frmAttach" Name="frmAttach" enctype="multipart/form-data" action="attachments.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="33554432" />

However, the insiduous php.conf (/etc/httpd/conf.d/php.conf) file used by default RPM install of Redhat httpd has a LimitRequestBody set to 512kB ("524288" ). Adjusting this to 32MB ("33554432") got things going for the larger files. Here is my php.conf file in its entirety. Hope this helps someone. L8er.

#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#

LoadModule php4_module modules/libphp4.so

#
# Cause the PHP interpreter handle files with a .php extension.
#
<Files *.php>
SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 33554432
</Files>

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
^^^ thats probably gonna help you the most.

Also, have you tried different browsers?
liquidkool
Forum Newbie
Posts: 9
Joined: Thu Feb 20, 2003 7:50 am

Post by liquidkool »

yes i have tried different browsers. It is definately the php.conf 512KB LimitRequestBody that is causing the problem. The question is if i dont have access to the file can it be changed at runtime?

Thanks for confirming my situation i was beginning to think i was the only one that had encountered such a problem. Very frustrating
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

you could try putting

Code: Select all

<Files *.php> 
SetOutputFilter PHP 
SetInputFilter PHP 
LimitRequestBody 33554432 
</Files>
into an .htaccess file, or maybe even just

Code: Select all

LimitRequestBody 33554432
liquidkool
Forum Newbie
Posts: 9
Joined: Thu Feb 20, 2003 7:50 am

Post by liquidkool »

Putting a .htaccess file in the same folder as the upload script doesn't seem to have and effect. I got the webmaster to change the php.conf file but i am just on a testing server so i want to find a work around incase i have the same problem when i switch servers.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

It works if I put it in an .htaccess file, that's odd.

I set it to '5' and i get:
Request Entity Too Large
The requested resource
-----------------
does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit.
--------------------------------------------------------------------------------

Apache/1.3.27 Server at -------- Port 80
Maybe it gets overridden by the php.conf, i don't know, im not a big linux guy.

LimitRequestBody 0, should make it unlimited though.
liquidkool
Forum Newbie
Posts: 9
Joined: Thu Feb 20, 2003 7:50 am

Post by liquidkool »

so in the directory where you upload script is you have a .htaccess file with LimitRequestBody 5 and it is giving you an error?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Correct. I wanted to set it really low to see if it would work at all.

I only put in that one line though, no <files> thing.
liquidkool
Forum Newbie
Posts: 9
Joined: Thu Feb 20, 2003 7:50 am

Post by liquidkool »

thats odd it has no effect.

file name : .htaccess
LimitBodySize 5

upload large files fine.
liquidkool
Forum Newbie
Posts: 9
Joined: Thu Feb 20, 2003 7:50 am

Post by liquidkool »

I have now gone back to the other server to check out the situation and i am actually getting an error #3. File only partially uploaded.

What could be causing this or how can it be fixed? Any ideas
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

LimitRequestBody 5, not LimitBodySize 5
liquidkool
Forum Newbie
Posts: 9
Joined: Thu Feb 20, 2003 7:50 am

Post by liquidkool »

That was just a type o on my part. I had limitrequestbody.

This other server must have a different configuration or linux version beause i can't find a php.conf file either.
Post Reply