Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lahore, Pakistan
    Posts
    150
    Thanks
    2
    Thanked 0 Times in 0 Posts

    how to rename file at run time

    i have a php form , in which i have some controls. On a form there is a "File Field" control. When user select any file from browse button, the file will be uploaded successfully.

    But i need some modifications.

    I want that when user upload a new file, the php code rename the file and add some random string with the file name.

    How can i do this, i spend many time on this module, but i am unable to do it.

    Please help in this regard.
    Thanks

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    I assume you are using copy() or move_uploaded_file() to move the temporary file (from $_FILES['fieldname']['tmp_name'] to somewhere else ?

    if so simply rename there

    PHP Code:
    <?php
    $u
    =uniqid(mktime()); //thats a big filename ;) best revise
    copy$_FILES['fieldname']['tmp_name'] , '/home/blah/'.$u.$_FILES['fieldname']['name']);
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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