views:

37

answers:

3

I make a php script that receive from POST 4 image, than store them and create the thumbs trought GD php library. The problem is that it works only if i load 2 photos 4mb each (or 4 photos 2 mb each, or less; in fact max 8 mb). why? i check the value of memory_limit (64mb), upload_max_filesize (25mb) and max_file_uploads (120secs), and if i increase them, nothing happen.

It seems that POST array is totally ignored : i see this because i put some "echo" on php script. The code is above :

if(($_FILES['userfile1']['tmp_name']!="") or ($_FILES['userfile2']['tmp_name']!="") or ($_FILES['userfile3']['tmp_name']!="") or ($_FILES['userfile4']['tmp_name']!="")) {
    // JPG/JPEG, max 4mb each
    for($i=1; $i<=4; $i++) {
        if ($_FILES['userfile'.$i]['tmp_name']!="") {
            $path_parts=pathinfo($_FILES['userfile'.$i]['name']);
            if(((strtolower($path_parts['extension'])=='jpg') or (strtolower($path_parts['extension'])=='jpeg')) 
            && ($_FILES['userfile'.$i]['size']<=4194304)) {
            } else {
                $wrong=1;
            }
        }
    }

    if(isset($wrong)) {
        $abort=1;
        $messaggio="Errore - Formato delle foto non valido. Assicurati che il formato sia jpg/jpeg e che la foto non superi i 3 Megabyte";
    } else {
        mkdir("./articles/photos/".$articleid);
        mkdir("./articles/photos/thumbs/".$articleid);
        $sql="";
        for($i=1; $i<=4; $i++) {
            if ($_FILES['userfile'.$i]['tmp_name']!="") {
                $photoid=$articleid."-".$i;
                $uploaddir="./articles/photos/".$articleid."/";
                $userfile_tmp=$_FILES['userfile'.$i]['tmp_name'];   
                $userfile_name=$_FILES['userfile'.$i]['name'];

                $userfile_name=$photoid."@".trim(str_replace(" ", "", $_FILES['userfile'.$i]['name']));

                $path_parts=pathinfo($_FILES['userfile'.$i]['name']);
                $photoondb=$photoid.".".strtolower($path_parts['extension']);
                move_uploaded_file($userfile_tmp, $uploaddir.$photoondb);

                // thumbs
                $name_new_image="./articles/photos/thumbs/".$articleid."/".$photoondb;
                $file = "./articles/photos/".$articleid."/".$photoondb;

                list($actualw, $actualh, $type, $attr) = getimagesize($file);
                if(($actualw>100) or ($actualh>100)) {
                    if($actualw>$actualh) {
                        $v1=$actualw/100;
                        $width=$actualw/$v1;
                        $height=$actualh/$v1;
                    } else {
                        $v1=$actualh/100;
                        $width=$actualw/$v1;
                        $height=$actualh/$v1;
                    }
                }
                $qualita=70;
                $new_image=imagecreatetruecolor($width, $height);
                $src_image=imagecreatefromjpeg($file);
                imagecopyresampled($new_image, $src_image, 0, 0, 0, 0, $width, $height, imagesx($src_image), imagesy($src_image));
                imagejpeg($new_image, $name_new_image, $qualita);

                imagedestroy($new_image);
                imagedestroy($src_image);

                if($sql!="") $sql.=", ";
                $sql.="('$articleid', '$photoondb')";
            }
        }
    }
}

I hope you can understand what i mean, more or less :)

+6  A: 

you missed one more parameter: post_max_size. its default is 8M...

kgb
+2  A: 

Two ways fix this problem

  • Change the php.ini

To make it work, I had to change the parameters

post_max_size = 8M
upload_max_filesize = 2M

to

post_max_size = 100M
upload_max_filesize = 100M
  • Add the below to your .htaccess file
php_value upload_max_filesize 10M
php_value post_max_size 20M
JapanPro
+3  A: 

There are two things you need to take care of: post_max_size and upload_max_filesize. They are both core php.ini directives.

Timwi