Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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:

    rename

    (PHP 3, PHP 4, PHP 5)
    rename -- Renames a file or directory
    Description
    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()
    <?php
    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:
    <?

    $handle 
    opendir("./");
    while((
    $file readdir($handle)) !== false){
    $newFile str_replace(" ""_"$file);
    rename("{$newFile}""{$file}");


    }


    ?>
    It has a bunch of errors... http://mynewdomainiscool.com/visualbasic/vb/rename.php

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

    http://us2.php.net/manual/en/function.rename.php

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 kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012