Without clean URLs ImageCache doesn't create folders or images

Jboo - March 22, 2009 - 16:31
Project:ImageCache
Version:6.x-2.0-beta10
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi, I'm after a bit of help. I've created 2 presets, but the folders aren't actually being created in the file system. The images I upload are being placed in the /sites/default/files folder, but when I try and view the file directly (eg, http://site.com/sites/default/files/image.jpg) I get a 404 not found.

Does anyone know what the problem might be?

Thanks in advance.

#1

kidsleep - March 24, 2009 - 20:49

JBoo,
Are you sure you have the correct permissions on the files folder? On the status screen does it show any actionable items?

#2

ecstasy2 - March 25, 2009 - 04:30

I am having the same issues

#3

Cybso - March 26, 2009 - 18:25

Same here (PHP on IIS). No failure in logs. Permissions are ok, uploads are possible.

#4

nakes - March 26, 2009 - 18:47

I've found that setting your file system to Private rather than Public, makes it work... but it affects other modules so not ideal solution.

So the issue should be about getting imagecache to work with the public file system.

#5

Jboo - March 27, 2009 - 10:58

I'm sure I tried changing the permissions to start with! However, I've just changed the files folder to 0777 permissions and now it works. Should it be 0777 or some other setting?

Thanks again.

#6

leenwebb - April 13, 2009 - 15:33

I am having this problem as well -- the files are being uploaded (and the thumb images created for display on the edit page) but no files are being created for the presets inside the imagecache folder. All files/folders are 777, the tmp folder is 777, the php.ini limit is very high (and I've never had any imagecache problems on this server with D5), and I am stumped. I have the latest ImageAPI and am using GD (not imagemagick).

Setting the file system to private works, but is wrong for my site for many other reasons.

#7

nakes - April 14, 2009 - 11:21

Refer to http://drupal.org/node/366177

I haven't tried it yet but will try when I get a chance later today...

#8

drewish - April 17, 2009 - 04:05
Component:imagecache_image module» Code

Okay so I'm guessing you've all don't have clean URLs and your doing public file transfers. Or am I wrong?

#9

rubenv - April 18, 2009 - 13:36

I am having this problem also, with the settings drewish described in comment #8 (No clean url + public file transfers).

#10

drewish - April 18, 2009 - 17:18
Title:No Imagecache folders and can't view images» Without clean URLs ImageCache doesn't create folders or images
Category:support request» bug report

right... currently the module requires that you either have clean urls or private files. i'm working on a patch but the current workaround is to use private files.

#11

drewish - April 29, 2009 - 14:53

marked #446470: Folders not being created as a duplicate.

#12

drewish - May 3, 2009 - 18:26
Version:6.x-2.0-beta8» 6.x-2.x-dev

marked #359387: broken preview on presets as a duplicate.

#13

ragavendra_bn - May 24, 2009 - 11:17
Version:6.x-2.x-dev» 6.x-2.0-beta9

Thanks Jboo. for comment #5

After adding a new preset to add text on images was added to product_full the default preset. Few images never got copied to .imagecache/product_full. Your trick to make 777 helped imagescopy after preset on product_full default preset folder for 6.x-2.0-beta9.

#5
Jboo - March 27, 2009 - 10:58

I'm sure I tried changing the permissions to start with! However, I've just changed the files folder to 0777 permissions and now it works. Should it be 0777 or some other setting?

Thanks again.

#14

firstov - May 28, 2009 - 01:38

running Drupal 6.12 with ImageCache 6.x-2.0-beta9. Getting 404 error and default home page in the browser when trying to access my_site.com/sites/site_name/files/imagecache/w_mark/imagecache_sample.png?1243474171 URL. (the URL to verify configuration of one of my presets I setup. Actually none of the presets work
Tried to set permissions to 777 for imagecache folder with no effect.
When tried to disable rewrite_engine=off directive in the files/.htaccess file, gotten Permission Denied error (since imagecache folder was empty and no index file was in there).
PHP 5.1.6 running on CentOS5. Any hints would be appreciated. Clean URLs are enabled.
"Private Files" is not an option for my site.

Please help! Thanks.

#15

firstov - May 30, 2009 - 02:27

just replying with more updates.
On the troubleshooting guide it says:
....
make sure the .htaccess file under your files directory contains exactly these two lines (no more no less):
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options +FollowSymlinks
.....
that's what made mine installation of imageCache to work just fine.

#16

ball.in.th - June 1, 2009 - 20:18

Hi,

I do have clean URLs enabled and public file access method. sites/default/files also has 777 permission.

However, after installing beta9, I tried to test my first preset and got 404 error (http://ball.in.th/sites/default/files/imagecache/test/imagecache_sample....). Then I checked sites/default/files and couldn't find imagecache directory at all. Am I missing something? I also tried disabling and re-enabling the module again; still got no imagecache directory. I did exactly the same thing on my windows box at home and it worked fine; but not on this Linux server.

My .htaccess in sites/default/files have these lines:
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options None
Options +FollowSymLinks

The "Options None" is not on the Troubleshooting page. Does it matter?
Also, I've noticed that the last new line character is missing in the .htaccess in sites/default/files. That is, the last line doesn't have a new line character (\n). Is this related?

Please help. Thanks.

#17

etcetera9 - June 1, 2009 - 19:02

I had Clean URLs and all file permissions was 777. But image cache wasnt working. Then I tried this about .htaccess file as mentioned at comment #15. Now it works!

Thanks...

Sinan

#18

ball.in.th - June 2, 2009 - 07:57

Continuing from my previous comment. A visit to admin/reports/status did create directory "imagecache" in sites/default/files (a message's shown on this page). However, it's empty. Creating a new test2 preset didn't help; still got 404 error (http://ball.in.th/sites/default/files/imagecache/test2/imagecache_sample...).

I've also tried removing "Options None" from .htaccess in sites/default/files and test with a new preset. That didn't work either.

Btw,

What could be wrong with my config?

#19

ball.in.th - June 2, 2009 - 13:46

Updates for my issue:

It turns out my hosting provider has a kind of setup that uses lighttpd, instead of apache, to serve image files. That's why a request to "nonexistantfile" returns a Drupal "page not found" error and to "nonexistantfile.jpg" returns a 404 error. I've asked my hosting to disable lighttpd and now ImageCache is working great!!

Also, my .htacess has these three lines and doesn't seem to cause any problem.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options None
Options +FollowSymLinks

PS. I used LiveHTTPHeaders to check the reply headers to realize that it's coming from lighttpd.

#20

sfdrummer - June 16, 2009 - 23:50

Well, I was having an awfull time trying to get this to work as I'm developing a site on a Shared IIS server. I had to resort to an ugly hack to get it to work properly:

Replace this:

function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = FALSE) {
  $path = _imagecache_strip_file_directory($filepath);
  $args = array('absolute' => TRUE, 'query' => $bypass_browser_cache ? time() : $bypass_browser_cache);
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
      return url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);
    case FILE_DOWNLOADS_PRIVATE:
      return url('system/files/imagecache/'. $presetname .'/'. $path, $args);
  }
}

With this:

function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = FALSE) {
  $path = _imagecache_strip_file_directory($filepath);
  $args = array('absolute' => TRUE, 'query' => $bypass_browser_cache ? time() : $bypass_browser_cache);
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
      return url($GLOBALS['base_url'] . '/index.php?q=' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);
    case FILE_DOWNLOADS_PRIVATE:
      return url('system/files/imagecache/'. $presetname .'/'. $path, $args);
  }
}

Then surf through all the images on your site so that the images are generated. Then turn it back, now all my images work fine.

Like I said, its ugly but there you go...

#21

schedal - July 15, 2009 - 21:47

Nothing worked, after 4 hours of trouble shooting:

1. Private vs public files, /tmp folder access correct
2. 777 permissions on files folder
3. uninstalled modules, re-added in single (correct) order
4. modified files/ htaccess file with over 4 different permutations
5. modified root htaccess file with RewriteBase on and off
6. tried manually creating folders

In my case, nothing could make the folder "imagecache" be created, or if I manually made it: for the files to be generated.

SOLVED by manually over-riding the function "imagecache_create_url" as per post #20 above.

I should note that I am on Apache not on IIS; my server is virtual and shared.

THANK YOU!!

I really hope that no one else will have to suffer as long a painful trouble shooting process as this as I just did...

Kindly,

Sebastian.

#22

snowbbdd - July 17, 2009 - 08:25

THANK!!!!! YOU!!!!!

#23

nestor718 - July 18, 2009 - 05:33

Please Note: This only works for windows server, IIS configuration with no clean URL's.

Hello guys! Not sure if this is 100% but it seem to work okay and builds on #20 code by actually testing if the file is really in the directory first right up in the public downloads select method. I've done a similar module for an ASP.NET project that checks a directory first for a file and if it didn't find it, it will generate on the fly.

I'm not sure what the big deal is about "clean" URL's but why would you need that to see if a file is at a given path anyway? On to the code

replace this:

<?php
function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = FALSE) {
 
$path = _imagecache_strip_file_directory($filepath);
 
$args = array('absolute' => TRUE, 'query' => $bypass_browser_cache ? time() : $bypass_browser_cache);
  switch (
variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case
FILE_DOWNLOADS_PUBLIC:
      return
url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);
    case
FILE_DOWNLOADS_PRIVATE:
      return
url('system/files/imagecache/'. $presetname .'/'. $path, $args);
  }
}
?>

With this:

<?php
function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = NULL) {
 
$path = _imagecache_strip_file_directory($filepath);
  if (
module_exists('transliteration')) {
   
$path = transliteration_get($path);
  }
 
$query = $bypass_browser_cache ? time() : $bypass_browser_cache;
  switch (
variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case
FILE_DOWNLOADS_PUBLIC:
    if (
file_exists($_SERVER["DOCUMENT_ROOT"] . "/" . file_directory_path() .'/imagecache/'. $presetname .'/'. $path)) {
        return
url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
    } else {
        return
url('system/files/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
    }

    case
FILE_DOWNLOADS_PRIVATE:
     return
url('system/files/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
  }
}
?>

There is a check there to see if the file is there or not. If it is, then the standard URL will be given, otherwise, the 'system/files/imagecache' path is invoked thereby generating the file. Other URL's will be unaltered.

About my sytem:

IIS 6
PHP 5
vbDrupal 5
No clean URL's (don't want to fork over the loot for the ISAPI rewrite)
Public downloads

Thing is, #20 hacks will always regnerate the files from one user location to another because the 'system/files/imagechace' path is always invoked (and none existent) so the files will always be regnerated. So we need to check if they are there and only generate if we need to. I think that's what imagecache was supposed to do, right? :)

#24

csc4 - July 17, 2009 - 22:46

I've been at this for 14 hours - and the change at #20 http://drupal.org/node/410200#comment-1709746 and then editing and saving (no changes) each of the presets has solved the problem for me too.

Specifically line 315 imagecache.module:
return url($GLOBALS['base_url'] . '/index.php?q=' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);

I have previews again!!

IIS server

#25

DrDaringPhD - August 3, 2009 - 11:55

I don't know anything about all these codes. Per the code post in #20, is it necessary to replace it with the original once done?

This is the only solution I've found that solves my nightmare with this issue. But it only works if I leave the code from #20 in place. The moment I revert back to the original code, all images are no longer displayed again.

#26

jicidre - September 4, 2009 - 13:38
Version:6.x-2.0-beta9» 6.x-2.0-beta10

I suscribe to comment #20
* Files directory with 777 access rights
* Clean URL in private
* imagecache and preset folders present.
* Using Drupal 6 on Apache and Linux.

The fix was to change the code as instructed in comment #20.
Note, the code on my 6.x-2.0 version was slightly different
You can see the commented and new files here

function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = FALSE) {
  $path = _imagecache_strip_file_directory($filepath);
  if (module_exists('transliteration')) {
    $path = transliteration_get($path);
  }

  $args = array('absolute' => TRUE, 'query' => empty($bypass_browser_cache) ? NULL : time());
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
    
      /*return url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);*/
      return url($GLOBALS['base_url'] . '/index.php?q=' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);
   
   case FILE_DOWNLOADS_PRIVATE:
      return url('system/files/imagecache/'. $presetname .'/'. $path, $args);
  }
    

#27

joachim - September 14, 2009 - 16:31

I can confirm that code from #26 fixes the problem for me on a Zeus server.

#28

thethanghn - September 30, 2009 - 13:00

I've tried #20.

- success in uploading files
- Fail in viewing image through jQuery modal dialog (this dialog represent binary data, not the image

#26 result in an error in file common.inc :(

#29

mtpultz - October 5, 2009 - 22:26

I'm having the same problem as you exactly. Some people are having things happen that are similar but yours is it exactly. What did you do to solve this? I tried all the .htaccess solutions and nothing. Haven't tried setting it to private as I don't know what will happen to the site if I did and I'm using clean urls.

#30

mtpultz - October 5, 2009 - 22:31

I had the same luck as Sebastian did... and unfortunately the same suffering

#31

hanoii - October 6, 2009 - 00:00

I think this is a duplicate of #241541: wrong url from imagecache_create_url() when no clean urls + public downloads, which is an old issue with a reported problem for D5, but the problem is current for D6.

Have a look at my patch in #21 of http://drupal.org/node/241541#comment-2118354 and comment if that fixes the problem in this issue. I'd think it should.

#32

wayne247 - October 27, 2009 - 02:18

I had almost the same issue as everyone else.

- Linux / Apache
- Drupal 6
- Ubercart 2
- ImageCache beta 10
- Clean URLs are enabled
- Files are set to private (i sell downloads, so quite mandatory)

When I was logged in as administrator, everything worked fine.

When I logged out as visited as guest, no images. I'd get a question mark in safari, blanks in firefox.

I went in imagecache.module, where posts #20 and #26 target, but went a different route. I took the line under the case "private files" and copied it over the case for "

See the final output of my function, with the original line commented out:

function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = FALSE) {
  $path = _imagecache_strip_file_directory($filepath);
  if (module_exists('transliteration')) {
    $path = transliteration_get($path);
  }

  $args = array('absolute' => TRUE, 'query' => empty($bypass_browser_cache) ? NULL : time());
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
      return url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);
    case FILE_DOWNLOADS_PRIVATE:
      return url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);
      //return url('system/files/imagecache/'. $presetname .'/'. $path, $args);
  }
}

and then BAM! images are there. Thanks to everyone for individual posts about their problems and how they fixed it. I'm adding my contribution to the lot in case someone has the bug I have.

There seems to be so many different configurations that no two person ever have the exact same bug.

#33

paljsingh - November 8, 2009 - 12:17

I too confirm.. #20

Apache/2.2.12 (Ubuntu)

No Clean URL, Public View

-Jitender Pal Singh

#34

ndmaque - November 8, 2009 - 14:47

i go with #20 - a dirty hack but needy
it drove me mad so i quickly wrote a jquery url changer as it seems better than a core hack.

$('img.imagefield-field_photo').each( function() {
  
   var new_src = $(this).attr('src').replace(/shop_photos/,'shop_thumbs') ;
   $(this).removeAttr('width') ;
   $(this).removeAttr('height') ;
   $(this).attr('src', new_src) ;

});

but decided to hard code it as first time visitors had problems

a little safer like this just in case they upgrade server or you upload your hacked imagcache.module to another site?

there's a value in variable table that tell us: variable_get('clean_url', 0)

<?php

   
case FILE_DOWNLOADS_PUBLIC:
    if(
variable_get('clean_url', 0) ) {  
      return
url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args) ;
    } else {
      return
url($GLOBALS['base_url'] . '/index.php?q=' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);
    }
?>

thanks for all your help

#35

daveplml - November 10, 2009 - 03:41

Edit: OK, so after playing around yet MORE with this module, here is what was necessary:

1. Enable Clean URLs
2. Make edits as above (not quite sure if #20 or #26 was required, but one of them seemed to work)
3. Manually create directories
4. chmod (set permissions on) directories to 777

Still, a lot of work and frustration went into this... I appreciate everyone's support, and really hope that in the future, this is running w/o so much trouble.

Most of all, lest it be forgotten, thanks for writing the module - it IS helpful - it's just a little rough around the edges.

Originally:

Giving up...

After playing with this for far too much time, I have to throw in the towel. I'm not an advanced Drupal admin - a medium-level user - and can't get this figured out.

My images just aren't showing, and the directories aren't being created. Is anyone working on a patch for this? I'm afraid to spend more time on this - hacking apart PHP files just isn't a good use of time!

Sorry for the frustration, hoping this gets fixed in a real release!

#36

suedehead - November 10, 2009 - 17:49

After hours and hours of pulling my hair out I've come to a solution - update ImageAPI to 6.x-1.x-dev. Everything works, no need to do the #20 or #26 solutions (which didn't work for me anyways).

#37

byronveale - November 20, 2009 - 20:58

I know it's already been said a ways back, but setting file system/download method to "private" worked for me...

 
 

Drupal is a registered trademark of Dries Buytaert.