即使正在上传多张图片,也只有一个缩略图图像会保存到此脚本的文件夹中。我认为它必须是与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';
}
}
答案 0 :(得分:0)
您是否可以更好地描述您希望脚本执行的操作。我认为你的问题可能在:
$original = ($tmp_file);
您正在覆盖在foreach循环中使用的变量。