Renaming files using PHP

Discussion in 'PHP' started by suhas93, Mar 7, 2010.

  1. suhas93

    suhas93 New Member

    Joined:
    Mar 7, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have a file on another server (say "something.com/1122.doc")

    Can I have a renaming engine (using PHP?) So, that when visitors click on download, the file should be renamed to somethingmeaningful.doc

    Suhas
     
  2. loyo

    loyo New Member

    Joined:
    Feb 12, 2010
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://bbs.prog365.com
    In your download script, you can give a new name to something.com/1122.doc, when somebody visited this script, it should copy the Original file to the target file,and then ,use the function header("location: newfilename path"); to visit the new file.
    <?php
    copy("1122.doc", "newfile.doc");
    header("location: newfile.doc");
    ?>
     
  3. suhas93

    suhas93 New Member

    Joined:
    Mar 7, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    thank you! thats a great idea!

    is there a script that deletes the file after download?

    ok i'm cheap :happy:
     
  4. loyo

    loyo New Member

    Joined:
    Feb 12, 2010
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://bbs.prog365.com
    try unlink("newfile.doc"); after performing header();
    I don't know whether it can achieve you need.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice