php - 正在工作的 PHP 图像函数现在正在生成所有黑色图像
问题描述
我多年来一直使用相同的代码,零问题。最近,我客户的服务器从 PHP 5 升级到 PHP 7,这破坏了许多项目。我以为这一切都解决了,但这个问题仍然存在。
这是我的功能。
function imageupload($filearray, $maxsize=0, $itemid=0){
$validtype=1;
$avalidtype=0;
$randfilename=sha1(microtime().rand(0,99999));
global $uploadDir;
global $dbh;
$fileid=0;
if ( (is_uploaded_file($filearray['tmp_name'])) && ($validtype==1)) {
$src=$filearray['name'];
$randfilename.=".jpg";
$file_name = $uploadDir . $randfilename;
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
copy($filearray['tmp_name'],$file_name);
if(preg_match('.jpeg',$src)||preg_match('.jpg',$src)) {
$src=imagecreatefromjpeg($filearray['tmp_name']);
}
elseif(preg_match('.png',$src)) {
$src = imagecreatefrompng($filearray['tmp_name']);
}
$src2=$file_name;
list($width,$height)=getimagesize($src2);
$thumbsize=getThumbSize($width, $height, 450);
$newwidth=$thumbsize[0];
$newheight=$thumbsize[1];
$awidth=$width;
$aheight=$height;
$new_name = $uploadDir . $randfilename;
$tmp= imagecreatetruecolor($newwidth,$newheight)
or croak("Cannot Initialize new GD image stream");
// list($twidth,$theight)=getimagesize($tmp);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
imagejpeg($tmp,$new_name,100);
imagedestroy($tmp);
}//end function
我已经验证正在传递的文件数组中填充了合法数据。我已验证调整大小功能正常工作。我已经验证要保存调整大小的图像的子文件夹确实具有适当的权限(我什至将它和父文件夹设置为 777)。
无论我上传 jpeg 还是 png,我仍然会得到空白黑框(尺寸正确)。这在 PHP 5 中可以完美运行——实际上也可以在多个其他服务器上运行。
我错过了什么明显的东西?
解决方案
推荐阅读
- aws-amplify - AWS Amplify 静态站点未按预期路由。需要一个最终的 url 需要一个最终的 '/'
- python - Rowcount 返回 1 但表中没有记录
- javascript - 如何使用 d3.js 和 angular 将 2d 条形图更改为 3d 条形图
- amazon-web-services - 无服务器 lambda 响应时间 Postman vs Deployed App
- python - 如何在列中搜索文本,然后使用该列使用 gspread 和 python 打印整行?
- javascript - One NGRX store, multiple Angular Applications
- python - 在python中与连接的输出并行运行2个循环
- powerapps - 我可以从 Power Apps 中的 Excel 工作表中获取下拉框的列表项吗?
- c++ - 有没有办法让两个具有不同访问权限的吸气剂并在其中一个循环中使用?
- javascript - 3个项目的localStorage json