The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 6 of 6

Thread: Change space to _

  1. #1

    Change space to _

    So I uploaded something to my server so people in my class can download. I need to make a little PHP script or what ever I can to change all the spaces in the name of the file to _'s because if not, they won't be able to download it. Can anyone hook me up?

  2. #2
    Change them when, when they are uploaded?

  3. #3
    No, I have them on the server right now, but I think if I run a PHP script that can rename the files it will work.. I need it to change spaces for _'s so let's say the file is called "Chapter 1 Exercise 02" ... I want it to be like this "Chapter_1_Exercise_02". Get it?

  4. #4
    I assume then the links to these files will be updated as well?

    In that case I assume you want something like:


    (PHP 3, PHP 4, PHP 5)
    rename -- Renames a file or directory
    bool rename ( string oldname, string newname [, resource context] )

    Attempts to rename oldname to newname.

    Returns TRUE on success or FALSE on failure.

    Example 1. Example with rename()
    rename("/tmp/tmp_file.txt", "/home/user/login/docs/my_file.txt");

    Note: Prior to PHP 4.3.3, rename() could not rename files across partitions on *nix based systems.

    Note: As of PHP 5.0.0 rename() can also be used with some URL wrappers. Refer to Appendix M for a listing of which wrappers support rename().

    Note: The wrapper used in oldname MUST match the wrapper used in newname.

    Note: Context support was added with PHP 5.0.0. For a description of contexts, refer to Reference CLV, Stream Functions.

    See also copy(), unlink(), and move_uploaded_file().

  5. #5
    Shouldn't this work?
    PHP Code:

    $file readdir($handle)) !== false){
    $newFile str_replace(" ""_"$file);


    It has a bunch of errors...

  6. #6
    Here is the page I got it from. Check out the user comments on the bottom of the page.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012