I am trying to create thumbnail of previously uploaded images using this function.
Original images are uploaded to mysite/used_uploads and thumbnails should be created at mysite/used_uploads_thb.
The thumbnail function is triggered directly after upload of the original.
I have also changed permissions with the directory, as follows, but the problem persists.
chmod("used_uploads_thb", 0777);
The directories are as follows:
mysite/used_uploads
mysite/used_uploads_thb
This is the whole script. The last step is giving the above error.
<?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);
?>
This is the error message:
Array
(
[type] => 2
[message] => imagejpeg(/used_uploads_thb): failed to open stream: Permission denied
[file] => /Applications/MAMP/htdocs/SiteCar/used_thumbnail.php
[line] => 26
)
I appreciate your help.