You are here: Home » PHP » Rename file name in PHP

Rename file name in PHP

29 Flares 29 Flares ×

When have to upload file in php, always rename file name.
If your file containing special characters like #, file could not be open in browser.
Some time you upload same file and not rename it, old one is replace with new.
To avoid it, rename file name with time() or some unique number.


<?php  $file= $_FILES['file']['name'];

$replace = array("#", "%", "^", "(", ")"," ","*","!","@","$");

$filename = str_replace($replace, "_", $file);

$newfile=time().$filename;
?>

About Abhishek Sinha

I am Abhishek and I love to code on PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Scroll To Top
29 Flares Twitter 2 Facebook 13 Google+ 10 StumbleUpon 2 Pin It Share 0 LinkedIn 2 29 Flares ×