Hi all,

I have had a problem with Imagecache and IIS. Digging into the code, I found the (my) problem. The function imagecache_create_url, on line 321 has the following code:

      return url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname . '/' . $path, $args);

If $path has a leading slash, this creates a URL that has two slashes together. IIS does not seem to like this. Removing the extra slash between $presetname and $path, it works perfectly for me:

      return url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname . $path, $args);

Does anybody know if $path has always a leading slash? Should this be checked before creating the URL, so that always a single slash is included?

Maybe this should be done too in the case of FILE_DOWNLOADS_PRIVATE, but I do not have any configuration with private downloads and IIS to test it.

Cheers,

Pedro

Comments

DissidentFool’s picture

I have the same double slash problem, only using various windows and linux versions of Apache, PHP, etc (so not an IIS specific issue). I personally found that adding the following line (obviously without php tags):

  if (substr($path, 0, 1) == '/') $path = substr($path, 1);

just before the return in the function _imagecache_strip_file_directory, in imagecache.module did the trick. I prefer to test for a leading slash and then remove it, rather than just drop a slash arbitrarily, as the normal code obviously works in some (most?) cases, so just removing a slash will likely break something else.

jaxxed’s picture

Status: Active » Needs review
Issue tags: +url relative

I like dissidentfool's solution. I would code it with stronger php declaration:

if (substr($path, 0, 1) == '/') { $path = substr($path, 1); }
?>

The patch would look something like ($ svn diff imagecache.module )

Index: imagecache.module
===================================================================
--- imagecache.module   (revision 5320)
+++ imagecache.module   (working copy)
@@ -338,6 +338,7 @@
  * Remove a possible leading file directory path from the given path.
  */
 function _imagecache_strip_file_directory($path) {
+  if (substr($path, 0, 1) == '/')  { $path = substr($path, 1); }
   $dirpath = file_directory_path();
   $dirlen = strlen($dirpath);
   if (substr($path, 0, $dirlen + 1) == $dirpath .'/') {

I'll mark this for review

verta’s picture

subscribing

jaxxed’s picture

I'll contact the module developor to see if he'd mind me applying this patch.

fizk’s picture

Status: Needs review » Closed (won't fix)

Reopen if this is still an issue.