我在裁剪图像时遇到问题,但是当我在某些代码更改为裁剪之前用于调整图像大小时,此源工作正常。
这是裁剪的来源:
$filenames1 = stripslashes($_FILES['txtfile1']['name']);
$exts1 = substr($images1, strrpos($images1, '.')+1);
$idimgs = md5(uniqid() . time() . $filenames1) . "-1." . $exts1;
$target_files1 = $target_dir . basename($idimgs);
list($width, $height) = getimagesize($filenames1);
$realImages = imagecreatefromjpeg($_FILES['txtfile1']['tmp_name']);
if ($width > $height) {
$y = 0;
$x = ($width - $height) / 2;
$smallestSide = $height;
} else {
$x = 0;
$y = ($height - $width) / 2;
$smallestSide = $width;
}
$thumbSize = 200;
$thumbImage = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumbImage, $realImages, 0,0,$x,$y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
imagejpeg($thumbImage,$target_dir.$idimgs);
imagedestroy($realImages);
imagedestroy($thumbImage);
如何解决这个问题?
PHP 无法直接从客户端系统访问文件。在这里,您正在尝试访问$_FILES['txtfile1']['name']
而是尝试getimagesize($_FILES['txtfile1']['tmp_name'])