【发布时间】:2019-08-31 18:27:41
【问题描述】:
我在后端使用php7.2-fpm和apache2服务器上传多张图片时出错,这只是很多图片中的几张图片,所以我想知道我的代码是否有任何问题,或者这个的真正问题是什么。 这是导致错误的代码:
function compress_image($source_url, $destination_url, $quality) {
$info = getimagesize($source_url);
if ($info['mime'] == 'image/jpeg')
$image = imagecreatefromjpeg($source_url);
else if ($info['mime'] == 'image/gif')
$image = imagecreatefromgif($source_url);
else if ($info['mime'] == 'image/png')
$image = imagecreatefrompng($source_url);
imagejpeg($image, $destination_url, $quality);
return $destination_url;
}
//Create Thumb Image
function create_thumb_image($target_folder ='',$thumb_folder = '', $thumb_width = '',$thumb_height = '') {
//folder path setup
$target_path = $target_folder;
$thumb_path = $thumb_folder;
$thumbnail = $thumb_path;
$upload_image = $target_path;
list($width,$height) = getimagesize($upload_image);
$thumb_create = imagecreatetruecolor($thumb_width,$thumb_height);
switch($file_ext) {
case 'jpg':
$source = imagecreatefromjpeg($upload_image);
break;
case 'jpeg':
$source = imagecreatefromjpeg($upload_image);
break;
case 'png':
$source = imagecreatefrompng($upload_image);
break;
case 'gif':
$source = imagecreatefromgif($upload_image);
break;
default:
$source = imagecreatefromjpeg($upload_image);
}
imagecopyresized($thumb_create, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width,$height);
switch($file_ext){
case 'jpg' || 'jpeg':
imagejpeg($thumb_create,$thumbnail,80);
break;
case 'png':
imagepng($thumb_create,$thumbnail,80);
break;
case 'gif':
imagegif($thumb_create,$thumbnail,80);
break;
default:
imagejpeg($thumb_create,$thumbnail,80);
}
}
这是我在 error.log 文件中遇到的错误提示
fcm.php 在第 157 行\nPHP 消息:PHP 注意:未定义变量: 第 160 行 fcm.php 中的 file_ext\nPHP 消息:PHP 注意:未定义 变量:第 137 行的 file_ext fcm.php\nPHP 消息:PHP 注意: 未定义变量:file_ext
等等,我想再次提一下,这种情况只发生在少数图片上,而不是全部,其余的都成功上传并创建了缩略图。塔恩克斯
【问题讨论】:
-
这可能是因为那些少数图像可能具有“区分大小写”的扩展名或 fpm 不支持的扩展名。如果某种类型的图像命中您的功能,请尝试在您的切换案例中调试您的逻辑所在的位置。您可以使用 echo / die 等。
-
好的,谢谢,我现在就尝试实现它
-
我尝试这样做,但这次没有错误不幸或幸运的是,但我注意到 Windows 上的一些东西,当我按类型应用排序时,这些没有上传创建缩略图的照片有点不同与窗口上的其他图像一起排序,即使它们具有所有相同的属性,这对我来说太奇怪了。
-
通过
print_r($source_url);检查您在 $_FILES 中获得的这些特定图像之一的内容
标签: php image thumbnails