Been testing the latest 4.7 imagecache with 4.7.6, clean url's. Imagecache working fine everywhere except for filenames with special characters, especially the # and & chars. The problem is that there are many other modules for uploading images (like upload etc.) which don't choke on these paths and the images are perfectlly viewable. With a gallery site, many users like to name files things like image #1, image #23 etc. I think the code is failing in the file_copy or file_move are, but I'm not sure. I thought I'd see if there is a simple workaround before I started looking in-depth. I've tried the usual variants of urldecode/encode, but the problem is that the cache file is not event getting created.
Thanks for any help.
Comments
Comment #1
chrisschaub CreditAttribution: chrisschaub commentedSorry, should be "the files are not EVEN getting created. Too early, not enough coffee.
Comment #2
quicksketchHave you tried passing the image through the imagecache theme function? You shouldn't ever be calling the image directly anyway because of this sort of problem, the theme function encodes it for you and saves a lot of typing:
Bad:
Good:
Comment #3
jeffsimm CreditAttribution: jeffsimm commentedHey Guys,
I can verify that this is happening in the 5.x-1.2 version as well. Give you an example I tried uploading a photo with the filename of JacksonHole_golf_G&T.jpg. It would show a broken image every time. Looking at the directory where the thumbnail and full-size images are saved, the file was not there. The file is not being created. I tested this in Firefox 1.5, 2 and IE 7 on WinXP.
Removing the "&" from the filename fixed the problem. The image was created and uploaded to the correct directory.
Not a huge deal, but it will make our editors job a little more difficult, having to remove these type of characters from every file name. Let me know if there is anything I can do to help. I appreciate it.
Thanks.
Jeff Simmonds.
Comment #4
Zach Harkey CreditAttribution: Zach Harkey commentedWhat if you need to know the size of the image outside of the image tag? (Something I find I need on a regular basis).
For example, What if I would like to contain the image in a div that is the exact width of the image, so that I can include a caption beneath it? How do you recommend achieving this kind of output:
This way the caption never exceeds the width of the image before wrapping. And the whole DIV can be floated inside another body of text.
Or what if you wanted to visibly display the image size, as you might on a photo download site?
For example:
As far as I know, the only way to make this information available to a template, outside of the image tag, is to do something like this (for second example above):
Is there a better way that I'm not aware of to achieve this?
Comment #5
Zach Harkey CreditAttribution: Zach Harkey commentedAlso, what if you just need the path and not the image? Like you would for a link, or background image?
For example:
Is there a better way than this:
And what about when you want to make a link directly to an image, as you might for a popup or lighbox?
The only way I know to achieve this (aside from using Drupal's l() function, which amounts to the same thing in this case) would be:
Comment #6
quicksketchYeah, imagecache doesn't provide a mechanism that just returns the path, that's a good point. It also seems that images are not created when the file contains an ampersand (I've not extensively tested). If you submit a patch to provide the path via an imagecache_ function I'll make sure it gets in. Confirming that it works with special characters put this to rest.
Comment #7
trevortwining CreditAttribution: trevortwining commentedI just wanted to ask if anyone had done anything further? If I could get a bit more detail about how the encoding is breaking the paths, I could take a stab at writing a patch if one doesn't exist yet.
Comment #8
Junyor CreditAttribution: Junyor commentedAccording to http://drupal.org/node/134201, imagecache fails if the filename contains a +, too.
Comment #9
izaak CreditAttribution: izaak commentedSubscribing. I am actually not sure if my problem is the same, it seems like either filenames with spaces are failing or files with pluses (or both).
Comment #10
themselves CreditAttribution: themselves commentedI'm having the same problem. While this isn't a site-destroying issue for me at the moment (if I notice a broken image, I just rename and reupload it for the user), it'd certainly be nice to get a fix for it. I think so long as we can support the characters that Windows allows in filenames, that should cover most of the Internet-using population. I guess full UTF-8 support is a bit much to ask ;)
Comment #11
Zach Harkey CreditAttribution: Zach Harkey commentedAfter much in-depth experimentation I finally found a solution that doesn't trip up on special characters like ampersands and spaces and can be implemented at the theme level.
In the second line of the function I changed
$path
todrupal_urlencode($path)
In template.tpl add the following function
Comment #12
themselves CreditAttribution: themselves commentedI tried this out, and it allows the file with spaces/whatever to upload ok, but it didn't generate any thumbnails for it. I could see the image if I went to the edit tab of the node, but yeah... nowhere else. I only changed the imagecache.module in one place;
Perhaps there's more places we need to add the url encoding? This is in 5.1 btw, i'm not sure if that makes a huge difference.
Comment #13
introfini CreditAttribution: introfini commentedIt also happens with the characters ( and ). I'm using 5.1
Regards,
introfini
Comment #14
introfini CreditAttribution: introfini commentedI'm sorry, i tested it better and it's ok with the '(' and ')'.
Thanks.
introfini
Comment #15
sunFYI: Regarding character encoding of uploaded files: Imagefield suffers from this, too.
Comment #16
sunThis is a Drupal core issue. You definitely should test Transliterate filenames module. Please report back if that module works for you (and mark this issue fixed if it does).
Comment #17
Junyor CreditAttribution: Junyor commentedIf it's a core issue, it needs to be fixed in core, not with another third-party module.
Comment #18
sunSure, you can try to convince core developers to implement a similar fix in Drupal. However, there have been many complaints about missing transliteration in core in the past. Furthermore, there are several transliteration projects and it is not yet clear which one works out best. Thus, this whole thing will need quite some time to hit core and like with any other core feature, it is initiated in contrib best.
There is quite much code needed for proper transliteration. Thus, if any file-related module would implement its own transliteration, the overall codebase would be bloated. file_translit intentionally includes that code bubble only if it is indeed required, so there should not be any performance issues. Additionally, this issue is about Drupal 4.7. Chances that any transliteration in D7 or D8 will be back-ported to 4.7 are nearly zero.
Comment #19
ms2011 CreditAttribution: ms2011 commentedFiles/URLs are not accessible if they contain reserved or non-ascii characters.
See url_generation.patch here http://drupal.org/node/43505#comment-316523
Comment #20
gollyg CreditAttribution: gollyg commentedsubscribe
Comment #21
dopry CreditAttribution: dopry commentedThis is a core issue. please install the transliteration module.
Comment #22
vgodard CreditAttribution: vgodard commentedFor drupal 6 just replace this
$imagecache_url = imagecache_create_url($namespace, $path);
with
$imagecache_url = imagecache_create_url($namespace, drupal_urlencode($path));
works really well !
Comment #23
peterparker CreditAttribution: peterparker commentedI have tried all of these suggestions, and while using beta 10 images with a + symbol do not display. Has there been any more progress on this front? I am using the transliteration module.
Comment #24
peterparker CreditAttribution: peterparker commentedYipeeeee.
I have finally found a solution to this problem, since none of the previous solutions were working for me.
Taking a cue from #22, in the imagecache.module I replaced
with
The difference is on line 4, where I substituted transliteration_get with drupal_urlencode.
While I am not altogether certain why #22 alone did not solve the problem, I am glad to have at least a temporary solution. Hope it can be of help to others.
Comment #25
mcurry CreditAttribution: mcurry commentedsubscribe
Comment #26
rv0 CreditAttribution: rv0 commentedsubscribe
Comment #27
beauz CreditAttribution: beauz commentedsubscribing, have a site where client has uploaded images with a & character and this has resulted in a broken link when viewing. I have used a workaround for now.
Comment #28
rv0 CreditAttribution: rv0 commented@ beauz
try installing transliteration module..