automatically rename uploaded file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rimkhalife
    New Member
    • Apr 2008
    • 1

    automatically rename uploaded file

    how to automatically rename the uploaded file if someone is coming to upload his file and if it has the name of anybody else file name i dont want the new to replace the old so i want the server to rename automatically the uploaded file.. thanks..
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by rimkhalife
    how to automatically rename the uploaded file if someone is coming to upload his file and if it has the name of anybody else file name i dont want the new to replace the old so i want the server to rename automatically the uploaded file.. thanks..
    Well, using file_exists() you'd check to see if the file name is already present - if it is you then assign a random name to it - rand() - and then save the file.

    Pretty simple :)

    Comment

    • aktar
      New Member
      • Jul 2006
      • 105

      #3
      [PHP]if (file_exists($_ FILE['name'])){

      //do something with the $_FILE['name']

      }

      move_uploaded_f ile ( $_FILE['temp_name', $_FILE['name'] )[/PHP]

      regards

      Comment

      Working...