0

即使正在上传多张图片,也只有一张缩略图保存到该脚本的文件夹中。我认为它一定与 foreach 循环的迭代有关。这只是下面发布的调整大小脚本。有没有人有一个快速修复?谢谢

define('THUMBS_DIR', 'C: /inetpub / wwwroot / mysite / images / thumbs / ');
define('MAX_WIDTH', 90);
define('MAX_HEIGHT', 100);
if (array_key_exists('upload', $_POST)) 
{
    $original = $_FILES['image']['tmp_name'];

    foreach ($original as $number => $tmp_file) 
    {
        $original = ($tmp_file);  
    }

    if (!$original) 
    {
        echo 'NoImageSelected'; 
    }
}  else { 
    list($width, $height, $type) = getimagesize($original);

    if ($width <= MAX_WIDTH && $height <= MAX_HEIGHT) 
    {
        $ratio = 1; 
    }   elseif ($width > $height) {
        $ratio = MAX_WIDTH/$width;
    } else { 
        $ratio = MAX_HEIGHT/$height; 
    }

    $imagetypes = array(' / . gif$ / ',' / . jpg$ / ',' / . jpeg$ / ',' / . png$ / ');
    $name = preg_replace($imagetypes, '', basename($file[$location]));     
    $moved = @ move_uploaded_file($original[$location], THUMBS_DIR.$file); 

    if ($moved) 
    {
        $result[] = $_FILES['image']['name'].'succesfullyuploaded';
        $original = $ext.$file[$location]; 
    }else{
        $result = 'Problemuploading'.$_FILES['image']['name'];
    }

    if ($type == 1) 
    {
        $source = imagecreatefromgif($original);
    } elseif ($type == 2) {
        $source = imagecreatefromjpeg($original); 
    } elseif ($type == 3) {
        $source = imagecreatefrompng($original);
    } else { 
        $result = 'Cannotidentifythefiletype';
    }
}
4

1 回答 1

0

您能否更详细地描述您希望脚本执行的操作。我认为您的问题可能出在:

$original = ($tmp_file); 

您正在覆盖您在 foreach 循环中使用的变量。

于 2013-10-21T06:35:07.180 回答