0

I have a thumbnail upload and crop script that uses JImage.
It normally works fine, but I have an install on a shared hosting, so I am using the Joomla ftp layer to combat file permissions problems.

However, I am getting the following error when trying to save to file

'Unable to open xxx/xxxx/xxx.jpg for writing, Permission denied'.

The final processed image file is not saved.

Here is my code:

$thumb = new JImage($uploadPath);
             $sourceWidth= $thumb->getWidth();
             $sourceHeight = $thumb->getHeight();

            $targetWidth = $width;
            $targetHeight = $height;

            $sourceRatio = $sourceWidth / $sourceHeight;
            $targetRatio = $targetWidth / $targetHeight;

            if ( $sourceRatio < $targetRatio ) {
                $scale = $sourceWidth / $targetWidth;
            } else {
                $scale = $sourceHeight / $targetHeight;
            }

            $resizeWidth = (int)($sourceWidth / $scale);
            $resizeHeight = (int)($sourceHeight / $scale);

            $cropLeft = (int)(($resizeWidth - $targetWidth) / 2);
            $cropTop = (int)(($resizeHeight - $targetHeight) / 2);



             $thumb=$thumb->resize($resizeWidth,$resizeHeight,true);
             $thumb=$thumb->crop($width, $height,0,0,true);


            $thumbpath = JPATH_SITE.DS.'images'.DS.'tours'.DS.'thumbnails'.DS.$id.'.jpg';
            $thumb->toFile($thumbpath,'IMAGETYPE_JPG');


            JFile::delete($uploadPath);

The image is uploading to my temp folder, and using $thumb->isLoaded() I know that there is an image loaded to the object, it is just the last toFile where it fails.

patterncatcher
  • 275
  • 2
  • 9
  • have you ensured the folder has 755 permissions and that you have folder ownership? – Lodder Nov 27 '13 at 09:12
  • yes, the folder is 755, I also have another image upload that just uploads the image to the folder with no processing, and that works fine. – patterncatcher Nov 27 '13 at 09:45
  • It is definitely a server side related issue. I have thoroughly tested your scripts with a few path changes to suits my needs and it works perfectly. Does the actual image your trying to process have 644 permissions? – Lodder Nov 27 '13 at 10:19
  • Yes, it is a server issue as the script works perfectly on other systems. The image is uploaded to a temp file, has 644 permissions, it loads into the JIMAGE object, but trying to write it to the folder does not work - uploading an image to the folder without using JIMage works. The error message says: "Unable to open '/var/www/vhosts/xxxxx/httpdocs/images/tours/thumbnails/71.jpg for writing: Permission denied" - what confuses me is 71.jpg is the new name of the image that doesn't yet exist in the folder – patterncatcher Nov 27 '13 at 10:31
  • Ok, I have discovered that SAFE_MODE is on for this hosting, which most probably is the cause. I have contacted the host to turn it off, and we'll see what happens. – patterncatcher Nov 27 '13 at 11:53

0 Answers0