wrong url from imagecache_create_url() when no clean urls + public downloads

matt2000 - April 1, 2008 - 22:44
Project:ImageCache
Version:6.x-2.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review
Description

The removal of this requirement was listed as a feature of 2.0, but derivative images are not being generated automatically. I am using CCK imagefield to display the images, which injects a /files/imagecache/preset/myimage.pic'>, but if the image doesn't exist, it's not created. However, if I enter ?q=files/imagecache/preset/myimage.pic into my browser address bar, the image will be created & displayed (on a blank white page, BTW, not inside Drupal.)

#1

dopry - April 2, 2008 - 15:18
Status:active» postponed (maintainer needs more info)

Well it obviously works without clean urls if it works with ?q=/path/to/file....
ImageCache injects the path to the imagecache image...

Are clean url's enabled or disabled on your site? This may be an issue with the theme function not printing properly if clean urls are disabled.

#2

matt2000 - April 7, 2008 - 03:57

It seems to be an issue with the CCK integration.

#3

Sharique - April 16, 2008 - 10:30

It is also not working ubercart. I'm using image field cck for for displaying product images. So it turns out to be a cck integration issue.
i'm using imagefield 2.x rc6.
--
Sharique

#4

dopry - April 15, 2008 - 15:24

@matt2000: just how is

It seems to be an issue with the CCK integration.

supposed to help anyone help you?

@safknw: umm get your own issue and don't post in this one again. please include some details about the problem you are having when you get your own issue. otherwise noone will be able to help you.

#5

dopry - April 19, 2008 - 17:07
Category:bug report» support request

I can confirm that clean-urls + imagecache are not your issue... can you detail how your file handling is configured, and how the views displaying the output work? can you paste the actual html output here? maybe the + some wrapping blocks?

#6

matt2000 - May 3, 2008 - 00:26

File downloads are set to private, stored in '../secure-files/' .

I've got it working now most of the time, but sometimes when the site is loaded by an anonymous user, all the cached images will disappear. (from the page, they still exist on the server.)

The nodes associated with the disappearing images do not have any restricted access.

Imagefield was set to save images in a subfolder of ../secure-files/, but changing this to the main directory doesn't seem to improve anything.

I'm not sure what you mean by "maybe the + some wrapping blocks" ?

Here's an HTML excerpt:

                        <div class="view view-success-stories"><div class="view-content view-content-success-stories"><div style="display: block; opacity: 0.9999;" class="nodearea success">
          <div class="success-thumb"><a href="/ibew229/?q=node/30">
<img src="http://uwsclient.com/ibew229/?q=system/files/imagecache/thumbnail/success_images/hunterstown+drawing.jpg" alt="" title="" class="imagecache imagecache-thumbnail">    </a></div>
    <div class="title"><a href="/ibew229/?q=node/30">Hunterstown Combined Cycle Gad Fired Power Plant Project</a></div>

    <div class="entrytext"></div>
     
 
</div>

     <div style="clear: both;"></div>
<div style="display: block; opacity: 0.9999;" class="nodearea success">
          <div class="success-thumb"><a href="/ibew229/?q=node/31">
<img src="http://uwsclient.com/ibew229/?q=system/files/imagecache/thumbnail/success_images/Sovereign+Bank+Stadium+3.jpg" alt="" title="" class="imagecache imagecache-thumbnail">    </a></div>
    <div class="title"><a href="/ibew229/?q=node/31">Sovereign Bank Stadium, Home of York Revolution Project</a></div>
    <div class="entrytext"></div>

</div>

#7

soxofaan - May 4, 2008 - 21:07
Title:Clean-URLs still required?» imagecache + CCK imagefield + clean-URLs
Version:5.x-2.0-beta» 5.x-2.0-rc2
Status:postponed (maintainer needs more info)» needs review

This is indeed an issue with imagefieldCCK integration

The formatters for imagefield generate (absolute) urls of the form http://example.com/path/to/files/imagecache/preset/image.jpg which obviously doesn't work when clean urls are not available (if the image does not exist before).

attached patch makes the formatters generate (relative) urls:
/path/to/files/imagecache/preset/image.jpg when clean urls are enabled
/?q=path/to/files/imagecache/preset/image.jpg when clean urls are disabled
works in my setup

AttachmentSize
241541_no_clean_urls_01.patch 708 bytes

#8

dopry - May 7, 2008 - 20:28
Title:imagecache + CCK imagefield + clean-URLs » file_create_url does not generate urls without clean urls enabled properly.
Project:ImageCache» Drupal
Version:5.x-2.0-rc2» 5.x-dev
Component:Code» file system
Category:support request» bug report
Status:needs review» needs work

If what you say is true, you patch is not fixing the right thing. file_create_url() should generate the proper URL to a file. You patch also will not generate URLs for private files at all since it doesn't use file_create_url.

#9

soxofaan - May 7, 2008 - 22:50
Title:file_create_url does not generate urls without clean urls enabled properly.» wrong url from imagecache_create_url() when no clean urls + public downloads
Project:Drupal» ImageCache
Version:5.x-dev» 5.x-2.0-rc2
Component:file system» Code

No, there is no problem with file_create_url(). For example, file_create_url('foo.bar') generates the following urls for the four possible combinations of clean urls and download methods:

No Clean URLs + public downloads  : http://example.com/path/to/files/foo.bar
Clean
URLs    + public downloads  : http://example.com/path/to/files/foo.bar
No
Clean URLs + private downloads : http://example.com/?q=system/files/foo.bar
Clean
URLs    + private downloads : http://example.com/system/files/foo.bar

This is correct behavior.

The three last cases are compatible with how imagecache works.

The problem lies however in the first case (no clean urls and public download).
With the current implementation, imagecache_create_url('preset', 'foo.jpg') would generate the url
http://example.com/path/to/files/imagecache/preset/foo.jpg
Because clean urls are not available, imagecache can't catch this request and the image won't be generated nor showed.

The url should be http://example.com/?q=path/to/files/imagecache/preset/foo.jpg, which can be picked up by imagecache.

So what imagecache_create_url('preset', 'foo.jpg') should generate is:

No Clean URLs + public downloads  : http://example.com/?q=path/to/files/imagecache/preset/foo.jpg
Clean
URLs    + public downloads  : http://example.com/path/to/files/imagecache/preset/foo.jpg
No
Clean URLs + private downloads : http://example.com/?q=system/imagecache/preset/foo.jpg
Clean
URLs    + private downloads : http://example.com/system/imagecache/preset/foo.jpg

This can't be obtained with just a file_create_url() call.

But I also agree that my patch of #7 does not works for private downloads, so this is still CNW.

Important side note (it took me some time to figure this out): to test the use cases of no clean urls, it is not enough to disable the clean urls option in the admin interface. Even if this setting is disabled, clean urls are still supported, they are just not generated by default by url() and l(). To really test this you should disable the rewrite module of the webserver or set a bogus RewriteBase in .htaccess for example.

#10

dopry - May 10, 2008 - 13:26

@soxofaan, if everyone filed issues like you my life could be much easier.... :) I'll try to work a patch asap.

#11

dopry - May 10, 2008 - 15:20

well there is a simpletest now... even though the issue is nor corrected... check DRUPAL-5--2 ...

#12

soxofaan - May 11, 2008 - 11:23
Status:needs work» needs review

Here is my take on the issue.

I changed imagecache_create_url() from

<?php
function imagecache_create_url($presetname, $path) {
  
$path = _imagecache_strip_file_directory($path);
  return
file_create_url(file_directory_path() .'/imagecache/'. $presetname .'/'. $path);
}
?>

to
<?php
function imagecache_create_url($presetname, $path) {
 
$path = _imagecache_strip_file_directory($path);
  switch (
variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case
FILE_DOWNLOADS_PUBLIC:
      return
url(file_directory_path() .'/imagecache/'. $presetname .'/'. $path, NULL, NULL, TRUE);
    case
FILE_DOWNLOADS_PRIVATE:
      return
url('system/files/imagecache/'. $presetname .'/'. $path, NULL, NULL, TRUE);
  }
}
?>

I also added some more documentation to the function.

I also worked on the simpletest test. Note that there is a method drupalVariableSet() that automatically stores the original values of Drupal variables and resets them after the test has run, so there is no need to do that tedious housekeeping yourself.

There is however still a tricky problem with the test. The function url() caches the clean_url setting per page request with an intern static variable. That means that it's futile to change the clean_url setting after url() has run once. The result is that the test are guaranteed to fail now ;)
I think the solution is to make a different page request per _ImagecacheCreateUrlTest() call. I'll have to look into this.

AttachmentSize
241541_imagecache_create_url_02.patch 7.68 KB

#13

dopry - May 11, 2008 - 23:59
Status:needs review» fixed

hmm that url() caching issue is annoying good catch... This one is totally committed.

#14

soxofaan - May 20, 2008 - 22:36
Version:5.x-2.0-rc2» 5.x-2.x-dev
Status:fixed» needs review

This patch fixes the problem with SimpleTest test mentioned in #12.

Now for each use case a node is created with the PHP evaluator on the body and a proper imagecache_create_url() call in the body. The node view, which is a separate page view, can now be checked if the generated URL is how it should be.

AttachmentSize
241541_imagecache_create_url_03.patch 8.12 KB

#15

casey - June 13, 2008 - 15:34

Do paths need to be absolute?

#16

dopry - July 9, 2008 - 03:09

committed to DRUPAL-5--2 and HEAD.

#17

drewish - October 29, 2008 - 21:49
Status:needs review» fixed

--project followup subject--

Anonymous (not verified) - November 12, 2008 - 21:57

Automatically closed -- issue fixed for two weeks with no activity.

--project followup subject--

Anonymous (not verified) - November 12, 2008 - 22:04

Automatically closed -- issue fixed for two weeks with no activity.

#18

Anonymous (not verified) - November 12, 2008 - 22:14
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#19

scifisi - September 24, 2009 - 13:33
Version:5.x-2.x-dev» 6.x-2.0-beta10
Status:closed» needs review

I'm having this problem as well. There is deffinately a problem here. It's either imagecache itself or an incompatability with another module and variables not being passed.

When I activate the imagecache module a directory is created in sites/default/files/imagecache - Fine. However if I create a preset arbitrarily called 'test' I would have thought that a directory called 'sites/default/files/imagecache/test' would be created - but it isn't.

I have a Prieview link which points to 'mysite.com/sites/default/files/imagecache/test/imagecache_sample.png?1253797544' there is no directory called test and no image called imagecache_sample.png - However!

imagecache_sample.png IS copied to /sites/default/files! Just not to /sites/default/files/imagecache/test.

It's as though the function imagecache_create_url in the file imagecache.module isn't working properly.

On line 321 there is the code:

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

Which for all intents and purposes looks to be ok.

I would like to find the code that saves out the imagecache_sample.png, then I think I could track down the problem slightly more easily - I'm new to PHP but have been a programmer for many years.

The fact that /imagecache/ is hard coded in there would mean to me that it 'must' be another routine or imagecache_sample.png would at least be saved there but it isn't.

This is what I have found so far:

http://www.caspianit.co.uk/imagecache-wrong-path/

And I will post my findings there - all comments gratefully received.

#20

scifisi - September 24, 2009 - 13:37

Sorry forgot to mention the modules I'm using - they are the latest as of 24/09/09

Drupal 6.14
imageapi-6.x-1.6.tar.gz
imagecache-6.x-2.0-beta10.tar.gz
imagefield-6.x-3.1.tar.gz

#21

hanoii - October 6, 2009 - 15:02
Version:6.x-2.0-beta10» 6.x-2.x-dev
Priority:normal» critical

I have this problem as well, I think this is a critical for the few of us who are not using clean URLs on some sites (will be probably changing that soon, but the bug is still there).

I tried to trace back the problem and it seems that in revision 1.100, the patch #366177: Imagecache seems to work only if the file system is set to private that was applied has some difference from the one in #12 which was probably only applied to D5 and I think the one applied has a bug.

The problem I think is just one line:

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

Problem is that the url() function treats absolute URLs (with http://) as external ones, and they don't get processed as internal drupal URLs to properly decide whether to add ?q= or not. Absolute URLs will be generated anyway by url() because the $args tells it so.

Following is the fix:

<?php
return url(file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);
?>

And attached is the patch

AttachmentSize
241541_wrong_url_without_cleanurls.patch 760 bytes

#22

tamasco - October 6, 2009 - 07:03

Hello hanoii,

Your patch is working perfectly for me. I just applied it and after flushing my presets, all imagecache images now display.
Thank you very much for your effort.

Cheers,
tamasco.

#23

abastida - October 6, 2009 - 14:52

The patch is working fine for me, as well. I was turning crazy until I found these thread. Thanks a lot, Hanoii

#24

florian.cathala - October 27, 2009 - 12:27

I had some trouble with a site behind a HTTP proxy. The path to the images was an absolute path http://internal.url/sites/[...]/image.png rather than http://external.url/sites/[...]/image.png or better, a relative path.

The problem was fixed with hanoii's patch + "absolute" arg set to FALSE.

Here is the patch.

AttachmentSize
241541_imagecache_create_url_04.patch 851 bytes

#25

UNarmed - November 9, 2009 - 14:58

Dude thanks a bunch!! i have been looking for something like this the entire day =D

Works like a dream!

#26

hanoii - November 20, 2009 - 21:23

Any follow-up on this issue from any of the developers? About the patch from #24, it makes sense that the URL are not absolute, or was there a reason for them to be?.

Also, just as a cross-link, I think the following issue #410200: Without clean URLs ImageCache doesn't create folders or images might be a duplicate or be also fixed by this issue. I left there a reference to this issue some time ago.

 
 

Drupal is a registered trademark of Dries Buytaert.