Closed (fixed)
Project:
Media Mover
Version:
5.x-1.0-beta11
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
3 Dec 2008 at 12:06 UTC
Updated:
19 Dec 2008 at 15:51 UTC
Let's say for filename myvideo.mov.flv or myvideo.mov.avi.flv, 1st 'extention' .mov is detected and the file may not be processed. But in actual fact the last extension should be returned.
Attached is the patch that fix that, make use of $path_parts['filename'] only for PHP5 and above, and a fall back for PHP4 is included.
| Comment | File | Size | Author |
|---|---|---|---|
| media_mover_extension.patch | 1.07 KB | ckng |
Comments
Comment #1
arthurf commentedThanks for the patch. The problem with this whole thing is that users can name their files what ever they please and it is really hard to figure out what is valid and what needs to be removed. I took a different approach than you did and removed all strings that match '.12345' assuming that file extensions are always 5 or smaller (eg: the improper mpeg4). This not perfect- really, we should use mime detect's list of file extensions and strip off anything that matches the mime detect functions, but there isn't currently a function in mime detect to do this (see: http://drupal.org/node/342189). Here's the solution I came up with:
Any thoughts?
Comment #2
delykj commentedAlso, would be great if you could use the Transliteration module to normalize filenames:
http://drupal.org/project/transliteration
Comment #3
ckngI think we don't need to remove other 'extensions' as it could be really part of a filename, and we can't control what user going to do with the filename or extension.
My suggestion would be to just take the last .ext. However, we can add in additional checking to make sure that the mime detected format equals the last .ext., and give a warning if they do not match.
Comment #4
ckngCorrect me if I'm wrong, from my understanding transliteration should work transparently when an upload occurred. Don't think we need to explicitly transliterate here.
Comment #5
arthurf commentedckng- where you say:
From what I understand of your concerns here, you want all extensions removed, not just the last one, correct? In this case we either have to guess what the extensions are, or we have to just use the last one.
So here's my propsal: we just do str_replace('.', '_', $filename) and append $new_extension on. This way we leave the "filename" intact, while avoiding the above concern.
How's that sound?
Comment #6
ckngActually, from my point of view, only last extension needs to be removed. The rest are IMHO user choice on naming their files.
And my example is wrong actually, let me try to explain again =)
For a conversion configuration of MOV => FLV
Take myvideo.flv.sometext.avi.mov as example - original code will stop at .flv and remove the rest of 'extension' leaving myvideo.flv and consider the file processed. IMO this is a wrong approach, in normal sense, myvideo.flv.sometext.avi should be the filename and .mov the extension, as any OS see it. So that's what my patch trying to do - only taking in the last extension (.mov) and leave the rest as it is (filename - myvideo.flv.sometext.avi). And the processed file will become myvideo.flv.sometext.avi.flv
Is that clearer?
As a side note, jquery media has the exact same problem, which should be fixed in its next release.
Comment #7
arthurf commentedSo would you be happy with something like:
While your solution is totally workable, I feel like this kind of approach is a bit cleaner- granted regexs are harder to read, but I think keeps things a bit more obvious
Comment #8
ckngRegex will do as well.
Comment #9
arthurf commentedSlight change to change white space to '_' as well. Fix is committed to D6 and D5. Thanks for the help!