PHP imagejpeg() 不会立即覆盖现有的图像文件。它确实有效,但在无限期之后,有时是一个小时或几个小时之后。在服务器更改并从 PHP5 升级到 PHP7 后,这种奇怪的行为开始发生。
写入权限被正确地赋予文件保存目标文件夹。还启用了 GD。
以下是我用来保存图像的代码片段。
/* Get original image x y*/
list($w, $h) = getimagesize($_FILES['file']['tmp_name']);
/* calculate new image size with ratio */
$ratio = max($width/$w, $height/$h);
$h = ceil($height / $ratio);
$x = ($w - $width / $ratio) / 2;
$w = ceil($width / $ratio);
$path = 'profimg/'.$width.'_'.$filename;
$imgString = file_get_contents($_FILES['file']['tmp_name']);
$tmp = imagecreatetruecolor($width, $height);
imagecopyresampled($tmp, $image,
0, 0,
$x, 0,
$width, $height,
$w, $h);
imagejpeg($tmp, $path, 100);
imagedestroy($image);
imagedestroy($tmp);
这可能是什么原因?