I have a basic script that allows my site members to upload short samples of their compositions for customers to listen to.
Some file names have spaces which obvi
$filename = str_replace(' ', '-', trim(addslashes($_FILES['userfile']['name'])));
Why addslashes
though? This also seems a little too simple -- am I missing something?
try;
$filename = trim(str_replace(" ","_", $_FILES['userfile']['name']));
After this line:
$filename = trim(addslashes($_FILES['userfile']['name']));
Write:
$filename = str_replace(' ', '_', $filename);
A filename like hello world.mp3 (two spaces) would come out as hello__world.mp3
(two underscores), to avoid this you could do this instead:
$filename = preg_replace('/\s+/', '_', $filename);