Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jan 2009
    Posts
    156
    Thanks
    47
    Thanked 0 Times in 0 Posts

    Adding underscores to mp3 filename in upload script

    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.

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

    PHP Code:
    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.
    Last edited by Daniellez; 03-10-2009 at 03:22 PM.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    str_replace(' ''_'$_FILES['userfile']['tmp_name'][$i]); 
    Thanks.
    Rafiki.

  • Users who have thanked rafiki for this post:

    Daniellez (03-10-2009)

  • #3
    Regular Coder
    Join Date
    Jan 2009
    Posts
    156
    Thanks
    47
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rafiki View Post
    PHP Code:
    str_replace(' ''_'$_FILES['userfile']['tmp_name'][$i]); 
    Thanks.
    Rafiki.
    Hi Rafiki,

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

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Just that line of code should replace any spaces with underscores.
    Thanks.
    Rafiki.

  • #5
    Regular Coder
    Join Date
    Jan 2009
    Posts
    156
    Thanks
    47
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rafiki View Post
    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?
    Last edited by Daniellez; 03-10-2009 at 03:16 PM.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    No it should be
    PHP Code:
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Daniellez (03-10-2009)

  • #7
    Regular Coder
    Join Date
    Jan 2009
    Posts
    156
    Thanks
    47
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    No it should be
    PHP Code:
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •