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 8959125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:22:34+00:00 2026-06-15T15:22:34+00:00

I am using Jquery uploader to upload images to my website. It uses a

  • 0

I am using Jquery uploader to upload images to my website. It uses a file called uploadhandler.php to manipulate the files. Inside the uploadhandler.php is the following function which appears to make changes to how the filename is formatted etc.
The problem I am having is if I upload a file with spaces in the file name it doesn’t appear to be removing the spaces in the file name. Does anyone know how I can edit it to add an extra command to remove any spaces in the file name, or point me in the right direction on how to do it ?.

 protected function trim_file_name($name, $type, $index, $content_range) {

    // Remove path information and dots around the filename, to prevent uploading

    // into different directories or replacing hidden system files.

    // Also remove control characters and spaces (\x00..\x20) around the filename:

    $file_name = trim(basename(stripslashes($name)), ".\x00..\x20");

    // Add missing file extension for known image types:

    if (strpos($file_name, '.') === false &&

        preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {

        $file_name .= '.'.$matches[1];

    }

    while(is_dir($this->get_upload_path($file_name))) {

        $file_name = $this->upcount_name($file_name);

    }

    $uploaded_bytes = $this->fix_integer_overflow(intval($content_range[1]));

    while(is_file($this->get_upload_path($file_name))) {

        if ($uploaded_bytes === $this->get_file_size(

                $this->get_upload_path($file_name))) {

            break;

        }

        $file_name = $this->upcount_name($file_name);

    }

    return $file_name;

}
  • 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-15T15:22:35+00:00Added an answer on June 15, 2026 at 3:22 pm

    The line:

    $file_name = trim(basename(stripslashes($name)), ".\x00..\x20");
    

    Will remove spaces “around” the filename, such as “foo ” because of the x20 bit which is a space. You could simply add directly after this line:

    $file_name = str_replace(" ", "", $file_name);
    

    Easy as that! Also remember, when you use the 2nd parameter in trim() you remove the “default” list of characters listed in the manual ( http://php.net/trim ) and replace it with your own …

    I would also point out, I would never use the filename as given by the browser in $_FILES[$x]['name'] … It simply opens too many questions and possibilities up. One technique to avoid the issue altogether might be to simply use the md5() or sha1() or similar of the file’s contents, example:

    $file_name = md5_file($_FILES['your_file_tag_name']['tmp_name']);
    

    That way in theory, you never ever have spaces in the files, or “dirty” filenames … And in addition, if a user uploads two files with the precise same contents, you simply need to check for the file’s existance, and if it already exists, you already have that exact same file. Hope this helps, this all assumes you’re doing file uploads, which I’m not 100% certain you are.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the great jquery-file-upload image uploader, but need to store images for different
I'm using the following file uploader with Rails 3: https://github.com/blueimp/jQuery-File-Upload The uploader on the
I am using Jquery Uploadify for images upload with PHP, here i have multiple
I'm using jquery file uploader (per blueimp) and I'm wondering how I can direct
I'm using plupload to upload files to my server ( http://www.plupload.com/index.php ), however I
I am using the multi-upload plugin found at: http://www.fyneworks.com/jquery/multiple-file-upload/ This is what I am
I would like to create a multifile file uploader using jQuery. Below is the
I have a script working to upload images without refreshing the page using jquery.form.js
I'm trying to get a simple file upload working using jquery-fileupload-rails carrierwave fog I
I'm pretty new to javascript and jQuery. I'm using Uploadify to upload images to

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.