...

View Full Version : Resolved Adding underscores to mp3 filename in upload script



Daniellez
03-10-2009, 03:45 PM
Hi,

Is there a way to have this script add underscores to mp3 filenames? E.G. If I rename I will follow.mp3 to "Iwillfollow.mp3" it works fine. Otherwise, I just get a file called "I" ...it ignores everything after the first space (doesn't even add the .mp3). Here's the upload code.


if (@move_uploaded_file($_FILES['userfile']['tmp_name'][$i], realpath($home_directory.$path)."/".$_FILES['userfile']['name'][$i]))

and


print "<input type='hidden' name=path value=\"".htmlentities($path)."\">";

I've tried adding str_replace(' ', '_', $string); and, while I'm not seeing errors, underscores are not added.

rafiki
03-10-2009, 03:49 PM
str_replace(' ', '_', $_FILES['userfile']['tmp_name'][$i]);
Thanks.
Rafiki.

Daniellez
03-10-2009, 03:54 PM
str_replace(' ', '_', $_FILES['userfile']['tmp_name'][$i]);
Thanks.
Rafiki.

Hi Rafiki,

In both places? I cannot try at the moment unfortunately.

rafiki
03-10-2009, 04:06 PM
Just that line of code should replace any spaces with underscores.
Thanks.
Rafiki.

Daniellez
03-10-2009, 04:10 PM
Just that line of code should replace any spaces with underscores.
Thanks.
Rafiki.

Sorry, I meant there are two locations where that can go (unless I'm misunderstanding this?) I'm still learning php and I'm struggling with the logic behind it.

if (@move_uploaded_file(str_replace(' ', '_', $_FILES['userfile']['tmp_name'][$i]), realpath($home_directory.$path)."/".str_replace(' ', '_', $_FILES['userfile']['tmp_name'][$i])))

I've added it twice in the example here...is this correct?

_Aerospace_Eng_
03-10-2009, 04:16 PM
No it should be

if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], realpath($home_directory.$path)."/".str_replace(' ', '_', $_FILES['userfile']['tmp_name'][$i])))
If it was erroring out there was a reason why you wouldn't notice. Its because you had @ before your move_upload_file call which suppresses any errors.

Daniellez
03-10-2009, 04:21 PM
No it should be

if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], realpath($home_directory.$path)."/".str_replace(' ', '_', $_FILES['userfile']['tmp_name'][$i])))
If it was erroring out there was a reason why you wouldn't notice. Its because you had @ before your move_upload_file call which suppresses any errors.

That worked, Thank You! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum