开发者

consuming memory by script on server

开发者 https://www.devze.com 2023-03-26 18:33 出处:网络
Image manipulation after file-uploading causes this error: Allowed memory size of 67108864 bytes exhausted (tried to allocate

Image manipulation after file-uploading causes this error:

Allowed memory size of 67108864 bytes exhausted (tried to allocate 20624 bytes) in .. on line 61

Line 61 is:

$imagem = imagecreatefromjpeg($plik);

On server memory limit is set on 32MB.

I wrote code like this:

<?php
$user   = $_POST['user_name'];
   $pass  = $_POST['pass'];
   $file = $_FILES['file']['tmp_name'];


   if ($user == "myuser" && $pass == "mypassword")
   {

    $directory='grafika/small'; 
    $dir=opendir($directory);
    $U = 1;
    while($file_name=readdir($dir))
    {
         if(($file_name!=".")&&($file_name!=".."))
        {
     开发者_如何学运维   $U += 1;
        }
    }

    closedir($dir);

    //------------------

    //------   

       list($width, $height) = getimagesize($file);
       $new_height_d = 600;
       $percent_d = $height / 600;
       $new_width_d = $width / $percent_d;
      if ($new_width_d > 1100){
          $percent = $new_width_d / 1100;
          $new_width_d = 1100;
          $new_height_d = $new_height_d/ $percent;

      }


       $percent_m =  $height / 113;
       $new_width_m = $width / $percent_m;

       $image_d = imagecreatetruecolor($new_width_d, $new_height_d);
       $image_m = imagecreatetruecolor($new_width_m, 113);

       $imaged = imagecreatefromjpeg($plik);
       $imagem = imagecreatefromjpeg($plik);

       imagecopyresampled($image_d, $imaged, 0, 0, 0, 0, $new_width_d, $new_height_d, $width, $height);
       imagejpeg($image_d,'grafika/big/'.$U.'.JPG');
       imagecopyresampled($image_m, $imagem, 0, 0, 0, 0, $new_width_m, 113, $width, $height);
       imagejpeg($image_m,'grafika/small/'.$U.'.JPG');
    //--------------------


    //


        $do_zapis =' <img class="mini" src="./grafika/small/'.$U.'.JPG" onClick="wys_big(\''.$U.'\')" alt="zaklin"/>';
        $file = "subpages/min_lista.html";
        $f = fopen($file, "a"); 
        flock($f, 2); 
        fwrite($f, $do_zapis); 
        flock($f, 3); 
        fclose($f);
    //-------------   


       echo('ok');

   }
   else{
       echo('not ok');

   }
   header("Refresh: 2; URL=edycja.php");
?>

And when i try to run it on server, uploading *.jpg file(less than 1MB) the error appears (see above).

So i'm thinking is there any way to reduce consumed memory or maybe this is normal?


You're just hitting a memory limit. Increase the memory limit (e.g. 256MB for image manipulation) and the problem should be gone.

Check your PHP.ini or raise the limit before you start with image manipulation:

ini_set("memory_limit", "256m -- 256 megabytes for image manipulation -- m");
0

精彩评论

暂无评论...
验证码 换一张
取 消