The forums have permanently moved to forum.kirupa.com. 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:

    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