I'm using Drupal 4.7.3 and I've encountered a problem with the upload module. I've tried searching the forums and issues and can't find anything relating to my problem. So I'm going to provide information about the problem and everything I've tested so far to try to get it to work. I've mainly been testing in Firefox, but the problems also occur in Internet Explorer.
I noticed that when I upload a file that, for example, is called "newsletter #1.pdf," the file will upload fine and it will be stored on the server in the correct directory, but when I click on the link it tells me the file cannot be found as it removes everything before the # symbol. I presume this is because # is used in URLs for other reasons.
I thought the problem could be solved if the file was just urlencoded. If the urlencoding changes the filename to "newsletter%20%231.pdf" then I can view the file with clean URLs on or off (so far I have only been able to do this by typing the URL in the address bar myself). It will not work if a space is changed to a "+". I've tried modifying the upload.module file to include urlencoding in the way other patches have suggested but that doesn't seem to do anything.
I have also implemented the modules found at http://coders.co.nz/drupal_development/?q=node/544 which allow me to view a list of all the files on the system. This list will URL encode the links to my files, but when I am using Clean URLs, it changes # to %2523 (even though Firefox tells me the URL has just %23, IE tells me the URL has %2523). The spaces are also changed to "+" instead of "%20", which I've already mentioned is a problem (both with Clean URLs enabled and disabled). Unfortunately the way these modules are implemented, the links will not work with a q?= before the file/ directory URL. If Clean URLs are disabled, Firefox tells me the URL it is pointing to contains the # symbol, which is then converted to %23 whereas IE tells me the URL contains %23 before I've clicked on the link.
Now, I could just rename the file before I upload it because I'm aware of this error, but someone else who is not aware may try to upload a file with a similar name and not know what the problem is.
Solutions to this problem I would accept include:
1. Properly URL encoding the link in the attachment list before I click on it; or
2. If there was a way to check the filename before it was uploaded to either
a) make sure a # symbol is removed from the filename or
b) give the user an error saying that the file cannot contain a # symbol and must be renamed before it is uploaded
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | munge.diff | 2.25 KB | GuruJ-1 |
Comments
Comment #1
GuruJ-1 commentedI ran into a similar problem with people using "&" in their filename, so I just strip out the most common troublesome characters by modifying upload.module (see attached diff).
It's not pretty, but it does the job.
Comment #2
demeritcowboy commentedJust confirming this bug is still there in version 5.1
Comment #3
benkewell commentedi have a similar problem when using chinese filename
as chinese characters take 2 bytes each and most of the bytes belongs to symbols in english encoding
so i think the problem is similar with the one descripted here
as stated above by u all , it should be a problem in the file renaming scheme of upload.module...
below is my problem's description originally posted in forum:
-----------------------------------------------------------------
hello~
i'm working on a drupal site in traditional chinese , which is a 2 byte encoding language
everything is fine but when i play with the upload module , problem occurs
i try to upload a file attached to a node using upload.module
when the filename is in english , it works fine
but if i upload a file with chinese filename , drupal rename the file for me
so it rename something like "xxx.mp3" into something like "mp3_0"
the file is uploaded successfully but when i download it through drupal
the browser treats the mp3 file as plain text as the file extension is missing
any work around for this?
i tried to turn on the mbstring func_overload for php ,
but as drupal warn me to turn it off in the admin panel
so i turn it off again and , neither on or off of this help
i guest it's only a problem with the rename scheme of upload.module
how could i solve this problem? as i'm not familiar much with drupal...
Comment #4
benkewell commentedand by the way , i'm using drupal 5.1 , php5 , apache2.2
linux with utf-8 encoding for file system on the server side
firefox 2 and windows vista on the client side
as both sides use utf-8 in default so i don't think the problem is caused by the os or browser...
Comment #5
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 #6
iarakawa commentedI have also the similar problem (the file extension becomes file name.) when using a Japanese filename.
I think Transliterate module is a good solution, but it does not work for us Japanese.
We need to have the filename uploaded as it is.
Thanks
Comment #7
iarakawa commentedThe problem was caused by file_check_upload in file.inc. If you use multibyte characters for the filename,
the file name becomes a file extension after file_check_upload function.
So after I changed one of codes, Upload works for multibyte characters.
I do not know if it is appropriate or not.
// $Id: file.inc,v 1.90.2.1 2007/05/31 05:48:58 drumm Exp $
** line 241
$file->filename = trim(basename($_FILES["files"]["name"][$source]), '.');
---> $file->filename = $_FILES["files"]["name"][$source];
Thanks.
Comment #8
smk-ka commented@iarakawa
This seems to be caused by PHP's limited unicode support, and won't be fixed until PHP 6. See http://bugs.php.net/bug.php?id=37738.
Comment #9
druvision commentedMoving the issue to drupal's core language system.
Comment #10
soxofaan commentedrelated issue (with patches): http://drupal.org/node/154245
Comment #11
brevity commentedthanks, http://drupal.org/project/transliteration fixed it for me on a sun, php without mbstring extension.
Comment #12
c960657 commentedThis is a duplicate of these issues:
#238299: file_create_url should return valid URLs (has patch, code needs review)
#278425: Using basename() is not locale safe (has patch, code needs work)