contao/test — Issue #1016: Safe Mode Hack don't addresses Image Resize Functions (imagejpeg() Errors during Upload)
Author: importer
Created: 2011-11-28 17:51:54+00:00
State: open
Labels: Defect, framework

When using Typolight (2.7.3) on a system where the Safe Mode Hack is required, there is an issue with uploading images that exceed the "max image size" (not to be confused with "max frontend image size") which is configured in the backend of Typolight.

These images are automatically resized by Typolight during/after the upload, but even with enabled Safe Mode Hack and correct directory and file permissions it fails with the following error

```
Warning: imagejpeg() [function.imagejpeg]: Unable to open '/var/kunden/webs/webXYZ/tl_files/dasbild.jpg' for writing: Permission denied in /var/kunden/webs/webXYZ/system/libraries/Controller.php on line 800
```

The issue is obviously caused because Apache runs as user www-data and the FTP user is different.

The issue is caused in row 800 in /system/libraries/Controller.php

```
imagejpeg($strNewImage, TL_ROOT . '/' . $strCacheName, (

![]($GLOBALS['TL_CONFIG']['jpgQuality'] ? 80 : $GLOBALS['TL_CONFIG']['jpgQuality']));
```

I tried adding the following before this imagejpeg command:

```
touch(TL_ROOT . '/' . $strCacheName);
```

but my touch also failed with the following error:

```
Warning: touch() [function.touch]: Utime failed: Operation not permitted in /var/kunden/webs/webXYZ/system/libraries/Controller.php on line 800
```

I guess that the Safe Mode Hack don't addresses the resize functions and we have to do some magic BEFORE modifying the images in order to fix this issue.

by the way, this is the output from the safe mode hack testing tool out of the typolight repository (just to show that my config is ok):

```
System temporary dir:
Checking tmpfile() ... success)
Creating TYPOlight temporary file system/tmp/d3380ed510f1989849f2bdf9e43d611d ... success

![](
Connecting to FTP server ... success)
Login with FTP username and password to server ... success

![](
Check for correct directory ... success)
Upload file smhcheck.dat ... success

![](
Check file smhcheck.dat ... success)
Delete file smhcheck.dat ... success

![](
Create directory smhcheck.dir ... success)
Delete directory smhcheck.dir ... success

![](
Delete TYPOlight temporary file system/tmp/d3380ed510f1989849f2bdf9e43d611d ... success)
Safe Mode Hack is enabled and appears to be working.
```

Just as a reference:
I initially reported this issue here:
http://www.typolight-community.de/showpost.php?p=15382&postcount=13

[Download the attachments](http://www.contao.org/tl_files/tickets/1016.zip "Download the attachments of this ticket")
Related issues: #1235, #1919

--- _Originally created by enemours on September 20th, 2009, at 10:27am (ID 1016)_