通过使用imagick创建一些缩略图,我发现了一个奇怪的错误。 我的php脚本接收一些以base 64编码的图片,将其保存到文件夹中,然后为每个图片创建一个缩略图。 这是我保存图片的代码:
$directory = getParentDirectory() . "/img/myfolder";
if (!is_dir($directory)) {
$res = mkdir($directory, 0777, true);
}
$ifp = fopen($directory . "/back.jpg ", "wb");
fwrite($ifp, base64_decode($back));
fclose($ifp);
//dx
$ifp = fopen($directory . "/dx.jpg ", "wb");
fwrite($ifp, base64_decode($dx));
fclose($ifp);
//front
$ifp = fopen($directory . "/front.jpg ", "wb");
fwrite($ifp, base64_decode($front));
fclose($ifp);
//sx
$ifp = fopen($directory . "/sx.jpg ", "wb");
fwrite($ifp, base64_decode($sx));
fclose($ifp);
createPreview($directory . "/back.jpg", $directory, "back");
createPreview($directory . "/dx.jpg", $directory, "dx");
createPreview($directory . "/sx.jpg", $directory, "sx");
createPreview($directory . "/front.jpg", $directory, "front");
这是crearePreview和getParentdirectyory代码:
function createPreview($image_path, $directory, $filename) {
$img = new Imagick($image_path);
$img->thumbnailImage(350, 350, true);
$img->writeImage($directory . "/" . $filename . "_prev.jpg");
}
function getParentDirectory() {
$currentwork = getcwd();
$parent = basename(dirname($_SERVER['PHP_SELF']));
return str_replace("/" . $parent, "", $currentwork);
}
但是当我调用createPreview时出现此错误:
11-18 10:32:28.662: I/JSON(23562): <b>Fatal error</b>: Uncaught exception 'ImagickException' with message 'unable to open image `/web/htdocs/www.mysite.it/home/old-site/sitefolder/img/myfolder/back.jpg': No such file or directory' in /web/htdocs/www.mysite.it/home/old-site/sitefolder/scripts/load_haircut_new.php:221
但如果我检查内部/ img文件夹,所有图片(原始大小)都已保存,但没有预览。想象力为何无法找到它?