0

私は画像アップロード スクリプトに取り組んでおり、この問題に遭遇しました。ImageMagick を使用すると、画像のサイズ変更とアップロードに時間がかかるため、次の 2 行を挿入しました。

set_time_limit(120);
ini_set('max_input_time', 120);

ただし、スクリプトは決して終了しません。データベースへのアップロード、サイズ変更、および挿入は正常に行われますが、ページは継続的に実行されます。これらは何らかの形で互いに矛盾しますか? 制限時間の120秒を超えてしまう。

編集: これは、スクリプトの完全な画像編集部分です。たとえば、1 つまたは 2 つの画像で機能しますが、より多くの画像を挿入すると (それにより時間がかかります)、機能しません。

set_time_limit(120);
ini_set('max_input_time', 120);
$resource = NewMagickWand(); 
MagickReadImage($resource,$image); 
MagickSetImageCompressionQuality( $resource, 100);
$resource = MagickTransformImage($resource,'0x0','660x500'); 
MagickWriteImage($resource, $image);
DestroyMagickWand($resource);

これは、アップロードするすべての画像を読み取るために使用するコードです: (reSizePic は上記のコードを呼び出す関数です)

$numberImages = count($_FILES['galFile']['name'])-1;

    for($i=1;$i<=$numberImages;$i++)
    {
    $imageName = $_FILES['galFile']['name'][$i];
                $imageType = $_FILES['galFile']['type'][$i];
                $imageSize = $_FILES['galFile']['size'][$i];
                $imageTemp = $_FILES['galFile']['tmp_name'][$i];
                $imageError = $_FILES['galFile']['error'][$i];

                //Make sure it is an image
                if(in_array(end(explode(".", $imageName)), $allowed))
                {
                     //Where to upload image to
                     $uploadFile = $uploadDir . $imageName;
                     if (file_exists($uploadFile))
            {
                //What to do if file already exists
                //Append random number to the end
                $front = explode(".", $imageName);
                $randomNum = rand(1,100);
                $front[0] = $front[0].$randomNum;
                $imageName = $front[0].".".$front[1];
                $uploadFile = $uploadDir . $imageName;
            }
                      if(move_uploaded_file($imageTemp,$uploadFile))
                      {
                      //Add $imageName to DB
                       $query = "INSERT INTO galleryImages VALUES(\"0\",\"$lastInsert\",\"$imageName\",\"$i\")";
                   mysql_query($query);
                   reSizePic($uploadFile);
                      }
                }



レヴィ

4

1 に答える 1

2

You should make sure to only call set_time_limit() once, as each time you call it, the timer will be reset.

For instance, if you call set_time_limit(30) 10 seconds in to your script, your script will run for a total of 40 seconds. So setting it on each resizePic() call is a bad idea.

于 2009-04-05T02:03:45.503 に答える