Currently, imagecache sets up two callback functions for the image paths:
1. A public filesystem callback on: file_directory_path() . "/imagecache
2. A private filesystem callback on: system/files/imagecache

The second callback seems to always work for people with the private file system.

The first callback can fail for a variety of reasons, most commonly:
a. Clean Urls is not enabled so the Drupal system never has a chance to intercept the file request
b. Your webhost has an alternate server handling the requests to image files

There are several patches floating around that "correct" the issue but they all result in imagecache serving the file for every request.

Here I put forward a quick change to allow imagecache to generate the file on a call to imagecache_create_url if the file system is private and clean urls is NOT enabled. The same code could instead be adapted to check for an imagecache admin option of "generate images on url creation".

In practice, imagecache_create_url is most commonly called to generate a url which the user's browser will immediately request, so even without the if statements, this shouldn't be much of a performance change. (With the exception that it could generate presets (but not deliver the image) on the private filesystem for users who do not have the "view preset" permission)

Just before the return line in imagecache_create_url, add:

  // if clean url is not enabled
  if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC && variable_get('clean_url', '0') == '0'){
		//this function checks if the derivative image already exists
		imagecache_generate_image($presetname, $filepath);
  }
CommentFileSizeAuthor
#1 no-clean-urls-1250156-0.patch715 bytessandrewj

Comments

sandrewj’s picture

StatusFileSize
new715 bytes

Adding patch file.

verta’s picture

I will try this patch as soon as I can. Thanks for posting.

fizk’s picture

Status: Needs review » Closed (fixed)

Please reopen if this is still an issue with ImageCache 6.x-2.0-rc1.