4

I have an extension, where I need to generate thumbnails. For this, I wrote kind of a wrapper function.

public static function pictureGenerator($file, $title, $size_w, $size_h) {
    $cObj = t3lib_div::makeInstance('tslib_cObj');
    $imgTSConfig = array();
    $imgTSConfig['file'] = $file;
    $imgTSConfig['file.']['width'] = $size_w . 'm';
    $imgTSConfig['file.']['height'] = $size_h . 'm';
    $imgTSConfig['altText'] = empty($title) ? 'preview' : $title;
    $imgTSConfig['titleText'] = empty($title) ? 'preview' : $title;

    return $cObj->IMAGE($imgTSConfig);
}

This function works fine, as long as I use a path relative to the TYPO3-Directory: Like: ../typo3conf/ext/sd_filmbase/res/images/default_film.jpg

But as soon as I try to use an absolute System-Path like the one below, no picture is generated anymore and "return $cObj->IMAGE($imgTSConfig)" returns NULL.
/var/www/vhosts/domain.com/httpdocs/path/to/picture/c.example.hq.jpg
This path is outside the TYPO3-Install-Directory - but is included within open_basedir (and safe_mode is Off).

I added the following path to open_basedir: /var/www/vhosts/domain.com/httpdocs/path/
And i tested with is_readable() if the file is readable from my extension - and it returned true.
Image Processing in the Install Tool works fine.

Do you have any idea, what else I could test? Or am I missing something essential?

Btw: I'm running TYPO3 4.6.1 and PHP 5.3.

SOLUTION:
Make a Symlink within Web-Directory to the external path. This Symlink has to be either within fileadmin/ or typo3conf/
See also konsolenfreddy's Post.

Stefan
  • 337
  • 6
  • 20
  • I don't get any error - return $cObj->IMAGE($imgTSConfig) just returns NULL – Stefan Dec 17 '11 at 10:33
  • I mean what is the error in your description above. You start a sentence with but as soon I use an absolute path but you never finished it. – Micromega Dec 17 '11 at 10:36
  • oh, how embarrassing, I'm sorry - my mind was quicker than my fingers it seems :-) I completed the text. – Stefan Dec 17 '11 at 10:49

1 Answers1

1

The IMAGE function will always expect a file relative to PATH_site either in typo3conf or fileadmin (see getFilename function in t3lib_tstemplate).

If you want to have an image outside your document root, two ways come to mind:

  1. put a symlink in a directory within typo3conf or fileadmin, e.g. fileadmin/myimages/, protect the directory content via .htaccess
  2. Use the Gifbuilder function directly. This might be cumbersome and might disable some higher level caching in the cObject.
konsolenfreddy
  • 9,551
  • 1
  • 25
  • 36
  • Now I get a really strange Core-Error-Handler-Message... For file_exists() it says open_basedir restriction in effect, although the destination-path for the symlink i just created, is already included in PHP's open_basedir-Configuration. I created a directory "thumbnails" in Web-Root and put two symlinks in there to the external folders. And accessing the file through a browser-request works, so the symlinks and the privileges should be ok I guess. – Stefan Dec 18 '11 at 14:27
  • Ok, I just found out, that IMAGE() doesn't work at all. It was just luck, that the local picture was returned unchanged. – Stefan Dec 18 '11 at 16:24
  • Solved! Thanks a lot! The problem was, that the files must either be within typo3conf/ or fileadmin/ - any other directory might not work (as in my case). – Stefan Dec 18 '11 at 17:01