Forum Moderators: coopster

Message Too Old, No Replies

PHP File Upload prob

Usual 512kb limit prob - but checked everything...

         

pboreham

10:12 am on Oct 4, 2005 (gmt 0)

10+ Year Member



Hi all,

I have my own dedicated Linux server and am trying to configure it to allow uploads larger than 512kb.

Currently, anything larger goes to a '404' page or hangs on a white screen - things that I am sure a lot of you are aware with using this function!?

Anyways, I have updated the following in Linux...

PHP.ini

MAX_FILE_SIZE, MAX_POST_SIZE, and the various time outs, memory variables - all set to above and beyond what I will need.

PHP.conf

Changed the LimitBodyRequest from 512kb to 32mb

HTTPD.conf

Checked for the LimitBodyRequest but it isnt there.

Finally, I've also set a MAX_FILE_SIZE hidden variable on my form to override anything I've forgot.

I've done all I can think of - restarted Redhat after the changes (which show ok online in phpinfo())

Really frustrating now... anyone got any other ideas?

Thanks for any help, Paul.

p.s. could I post the PHP.ini for anyone to look at?

RonPK

1:46 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just checking:
* you meant post_max_size
* you meant upload_max_filesize
* you're using enctype="multipart/form-data" in the form tag?

Could there be something wrong with the script you're using to handle the upload?

pboreham

2:01 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



Hi Ron,

Thats them!

I think the script is pretty solid - as I say, it uploads anything sub 512kb with no probs.

It must be a LimitBodyRequest problem, but I have altered that value in the php.conf file.

Is there anywhere else I should be looking for this value - i.e. should I actually ADD it to httpd.conf even though currently it isnt in there at all?

Thanks for any help, Paul.

RonPK

4:00 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LimitBodyRequest must be some setting special for your distribution, as I can't find anything on it in the Apache documentation. What happens if you simply comment it out?

pboreham

4:24 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



Ah, its LimitRequestBody...

I have commented it out anyway and just restarting the server so will let you know!

Thanks for the reply,

Paul

RonPK

4:35 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Ah its LimitRequestBody...

;)

pboreham

4:51 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



Nope, had no effect :-(

Crazy, I dont know what else I can do...

dreamcatcher

5:12 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You want to post your upload code pboreham? Maybe someone can spot something you might have missed.

RonPK

5:25 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there any message in your server's error log?

pboreham

5:28 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



Just got home, so will post these when I get back to the office in the morning.

Thanks for helping chaps!

pboreham

7:38 am on Oct 5, 2005 (gmt 0)

10+ Year Member



Hi Guys,

Here is the code to upload the image as requested...

if(isset($_POST['Submit']))
{
$size = 150; // the thumbnail height
$filedir = '../images/'; // the directory for the original image - '../images/'
$thumbdir = '../images/'; // the directory for the thumbnail image
$prefix = 'small_'; // the prefix to be added to the original name
$mode = '0666';
$userfile_name = $_FILES['image']['name'];
$userfile_tmp = $_FILES['image']['tmp_name'];
$userfile_size = $_FILES['image']['size'];
$userfile_type = $_FILES['image']['type'];
if ($_FILES['image']['name']!="")
{
$prod_img = $filedir.$userfile_name;
$prod_img_thumb = $thumbdir.$prefix.$userfile_name;
move_uploaded_file($userfile_tmp, $prod_img);
chmod ($prod_img, octdec($mode));
$sizes = getimagesize($prod_img);
$aspect_ratio = $sizes[1]/$sizes[0];
if ($sizes[1] <= $size)
{
$new_width = $sizes[0];
$new_height = $sizes[1];
}else{
$new_height = $size;
$new_width = abs($new_height/$aspect_ratio);
}
$destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image');
$srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image');
ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing');
ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');
imagedestroy($destimg);
}

}

As I mentioned, this script uploads <512kb files fine...

Any help to anyone?

Cheers, Paul

RonPK

8:20 am on Oct 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you need to find out whether the script gets called at all. That way you'll know whether the problem is in the web server or in the script. Normally, PHP isn't executed before the web server finishes the upload.

So try putting something like this at the top of the script:
<?php
echo 'hi there';
print_r($_FILES);
die;

Upload a file, and see what happens.

pboreham

8:33 am on Oct 5, 2005 (gmt 0)

10+ Year Member



Hi Ron,

The script definately gets called - I have already put a debug echo inside the function loop that echos when an image is uploaded.

Plus, images under 512kb get uploaded fine.

I am sure it must be to do with the LimitRequestBody in the php.conf file.

I have tried changing the value, commenting the whole thing out and even removing the variable all together with no effect.

I have restarted the web server after each change - is there anyway I can check the value has stuck in PHP?

RonPK

10:06 am on Oct 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe someone in the Apache forum [webmasterworld.com] can help...