Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7946257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:05:53+00:00 2026-06-04T01:05:53+00:00

I have a basic script that allows my site members to upload short samples

  • 0

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 obviously causes problems when trying to play the samples. Is there a way to replace these spaces with underscores between uploading to the temp directory and moving the file to the ‘samples’ directory?

<?
            $url = "http://domain.com/uploads/samples/";
            //define the upload path
            $uploadpath = "/home/public_html/uploads/samples";
            //check if a file is uploaded
             if($_FILES['userfile']['name']) {
              $filename = trim(addslashes($_FILES['userfile']['name']));
            //move the file to final destination
              if(move_uploaded_file($_FILES['userfile']['tmp_name'],
            $uploadpath."/". $filename)) {

              echo "

    bla bla bla, the final html output

            ";

              } else{
                if ($_FILES['userfile']['error'] > 0)
              {
                   switch ($_FILES['userfile']['error'])
                {
                  case 1:  echo 'File exceeded upload_max_filesize';  break;
                  case 2:  echo 'File exceeded max_file_size';  break;
                  case 3:  echo 'File only partially uploaded';  break;
                  case 4:  echo 'No file uploaded';  break;
                }
                exit;
              }
              }
            }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:05:55+00:00Added an answer on June 4, 2026 at 1:05 am

    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);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a very basic JQuery script accompanied by some CSS that helps
I have written a pretty basic upload script that takes the file and uploads
I have a very basic script that calculates and changes the width of a
I have a PHP script that does basic encryption of a string through the
I have a pretty basic java applet that allows users to use a signature
I have this basic script that makes an element show onmouseenter, and hide onmouseleave.
I have a basic php script that calls system(netstat -l) and the reads what
I have a basic PHP script that displays the file contents of a directory.
I have a very basic python script that does HTTP connection. import socket def
I have a very basic script that sets up datepicker on three of my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.