valid filenaming
Posted: Sat May 17, 2008 2:00 pm
I've got a website where people have uploaded mp3s over the past couple years. I'm looking to revamp a whole lot of the site because I basically learned php while developing it and it's loaded with every poor design decision you can imagine. I'm looking for critiques on my method before I implement it.
My filenaming convention is "TrackID ArtistName - TrackTitle.mp3" renamed from whatever the uploaded files' original names were using user info and the TrackTitle entered in the upload form. Up until now my HTML charset has been undeclared and I am now switching it to utf8. So I will be using from the phputf8 library.
I alos know DOS/Windows will reject the following characters \ / : * ? " < > |
From what I can tell Apache will let you do whatever you want. If you have a backslash (/) in the filename it will just create necessary folders to make it work and the file is still accessible in that way.
I don't know anything about the Mac platform.
To negate the invalid ascii characters I came up with this --
However, now that I am thinking about it, could users enter ascii command characters in the Track Title field? Is that something to worry about?
Any feedback on this concept would be appreciated!
My filenaming convention is "TrackID ArtistName - TrackTitle.mp3" renamed from whatever the uploaded files' original names were using user info and the TrackTitle entered in the upload form. Up until now my HTML charset has been undeclared and I am now switching it to utf8. So I will be using
Code: Select all
$filename = utf8_accents_to_ascii($filename);
$filename = utf8_strip_non_ascii($filename);I alos know DOS/Windows will reject the following characters \ / : * ? " < > |
From what I can tell Apache will let you do whatever you want. If you have a backslash (/) in the filename it will just create necessary folders to make it work and the file is still accessible in that way.
I don't know anything about the Mac platform.
To negate the invalid ascii characters I came up with this --
Code: Select all
function DOSfriendly($filename) {
$filename = str_replace(array("\\","/",":","*","?",'"',"<",">","|"),
array( "µ","¶","~","¤","¿","¨","(",")","I"),$filename);
return $filename;
}Any feedback on this concept would be appreciated!