Imagecache is creating duplicate images for files with spaces in the name. I can't figure out if it is a .htaccess rule causing the issue, or if its likely to be something else. The .htaccess is pretty standard with a rule to turn of mod_security conflicts.

It seems every request results in a new file but only when spaces are in the filename. The file gets listed as www.Mysite.com/files/imagecache/gallery_fullsize/files/gallery-images/la... in the page source. The file in question is called laura s.jpg.

The issue node/129433 caused the path to be put through drupal_urlencode() eg drupal_urlencode($path) to be added to the imagecache function. Removing it allows my image to appear without the duplication, but i guess it opens it back up to the problems with other characters in the filename. How can i fix this?

I'm using Drupal 5.2 on Linux with Apache.

Im considering overridding the file_create_name function in file inc to make sure files have any spaces removed, but that may not be possible.

Thanks,
Drew

Comments

dopry’s picture

Status: Active » Postponed (maintainer needs more info)

Does the transliterate filename module solve your problems?

dopry’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

inactive over a month.

wolv3rin3’s picture

drupal: 5.6
imagecache.module,v 1.19.2.28 2007/06/16 17:22:41 dopry Exp

quick workaround/patch:

In case you already have uploaded a lot of problematic files (with space in their filename):

1) download and install the transliteration module
http://drupal.org/project/transliteration

2) enabled the transliteration module (which will fix future upload problem)

3) replace the original theme_imagecache function by this one:

function theme_imagecache($namespace, $path, $alt = '', $title = '', $attributes = NULL) {
  $attributes = drupal_attributes($attributes);
  if (module_exists('transliteration'))
  $imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. transliteration_get($path));
  else
  $imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path);
  return '<img src="'. $imagecache_path .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' />';
}

this will use the transliteration module to encode the filename

4) flush your imagecache preset

drew reece’s picture

FWIW,

Transliteration seems to be doing the job well, I didn't get around to testing until I recently upgraded the Drupal core.

Thanks.
Drew

idflorin’s picture

this is not working for me at Modern Dandies :(

drew reece’s picture

Transliterate will only work for new files, not ones existing uploads on the server.

Please elaborate on what you are seeing, what you have tried.

Drew

idflorin’s picture

Version: 5.x-1.3 » 5.x-2.0-beta

I installed the patch from #3.
I edited few posts and added new images.
I flushed again the presets but :( no success.

No errors where generated.

drew reece’s picture

It seems like the transliteration module isn't working for you. Test with the uploading files, since I can say that should work, I haven't used the function @3 so I can't say if that is correct.

If it doesn't work try a clean test install to eliminate problems with other modules or patches you may have in your Drupal install.

Drew