【发布时间】:2015-06-30 05:20:11
【问题描述】:
我正在尝试使用this 函数创建以前上传的图像的缩略图。
原始图像上传到 mysite/used_uploads,缩略图应在 mysite/used_uploads_thb 创建。
原图上传后直接触发缩略图功能。
我也更改了目录的权限,如下,但问题依旧。
chmod("used_uploads_thb", 0777);
目录如下:
mysite/used_uploads
mysite/used_uploads_thb
这是整个脚本。最后一步是给出上述错误。
<?php
$src = substr($filePath, 1);
//$src example: used_uploads/252-558ec2e5dc45c-alfa-romeo-giulia - 2.jpg
chmod("used_uploads_thb", 0777);
$dest = '/used_uploads_thb';
$desired_width="100";
function make_thumb($src, $dest, $desired_width) {
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
/* create the physical thumbnail image to its destination */
imagejpeg($virtual_image, $dest);
print_r(error_get_last());
}
make_thumb($src, $dest, $desired_width);
?>
这是错误信息:
Array
(
[type] => 2
[message] => imagejpeg(/used_uploads_thb): failed to open stream: Permission denied
[file] => /Applications/MAMP/htdocs/SiteCar/used_thumbnail.php
[line] => 26
)
感谢您的帮助。
【问题讨论】:
-
以斜杠开头的路径(
'/used_uploads_thb',称为绝对路径)和不以斜杠开头的路径('used_uploads_thb')之间存在很大差异。您应该使用明确以__DIR__开头的路径。 -
@DCoder,谢谢。 chmod 只会将其作为 (used_uploads_thb) 接受,而 imagejpeg 不起作用,除非它也按照我的代码使用。
标签: php thumbnails