here is my code
$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);
}
I keep getting this error
Warning: imagejpeg(C:\xampp\folders\thumbs): failed to open stream: Permission denied in C:\xampp\folders\index.php on line 32
The destination file has read and write permissions! Whats wrong with my code
The second parameter of imagejpeg should be the name of a file and not the name of a directory (in your code $thumb_path
seems to be a directory). Moreover, you should escape the backslashes (write \\
instead of \
for a single backslash). Therefore, replace
$thumb_path = "C:\xampp\folders\thumbs\";
with
$thumb_path = "C:\\xampp\\folders\\thumbs\\".basename($image);
and I hope your problem is solved.
there is a permission error, change the permissions of 'thumbs' folder to 775;