这是我的代码
$img_dir ="C:\xampp\folders\img\*.jpg";
$thumb_width = 100;
// Open a known directory, and proceed to read its contents
$scan= glob($img_dir);
foreach($scan as $image) {
$im= imagecreatefromjpeg($image);
$img_width = imagesx($im);
$img_height=imagesy($im);
$thumb_height= floor ($img_height *($thumb_width/$img_width));
$new_img=imagecreatetruecolor($thumb_width,$thumb_height);
imagecopyresized($new_img, $im, 0,0, 0, 0, $thumb_width, $thumb_height, $img_width, $img_height);
$thumb_path = "C:\xampp\folders\thumbs\";
imagejpeg($new_img,$thumb_path);
}
我一直收到此错误
Warning: imagejpeg(C:\xampp\folders\thumbs): failed to open stream: Permission denied in C:\xampp\folders\index.php on line 32
目标文件具有读写权限!我的代码出了什么问题
答案 0 :(得分:0)
imagejpeg的第二个参数应该是文件的名称,而不是目录的名称(在代码中$thumb_path
似乎是一个目录)。此外,您应该转义反斜杠(对于单个反斜杠,请写\\
而不是\
)。因此,请替换
$thumb_path = "C:\xampp\folders\thumbs\";
与
$thumb_path = "C:\\xampp\\folders\\thumbs\\".basename($image);
我希望你的问题得到解决。
答案 1 :(得分:0)
存在权限错误,请将'thumbs'文件夹的权限更改为775;