php - Is their anyway I can replace the filename to MD5 -


i working on small upload script. but, when file uploaded upload directory. file name same name of file uploaded. possible rename random digits md5. thanks!

<?php  require 'header.php';  ?>  <center> <?php $target_dir = "uploads/"; $target_file = $target_dir . basename($_files["filetoupload"]["name"]); $uploadok = 1; $imagefiletype = pathinfo($target_file,pathinfo_extension); // check if image file actual image or fake image if(isset($_post["submit"])) {     $check = getimagesize($_files["filetoupload"]["tmp_name"]);     if($check !== false) {         //echo "file not image.";       //  $uploadok = 1;     } } ?> <br> <?php // check if file exists if (file_exists($target_file)) {     echo " sorry, file exists or";     $uploadok = 0; } ?> <br> <?php // check file size if ($_files["filetoupload"]["size"] > 5000000) {     echo "sorry, file large.";     $uploadok = 0; } // allow file formats if($imagefiletype != "jpg" && $imagefiletype != "png" && $imagefiletype != "jpeg" && $imagefiletype != "gif" ) {     echo "sorry, jpg, jpeg, png & gif files allowed.";     $uploadok = 0; } // check if $uploadok set 0 error if ($uploadok == 0) {     echo "your file not uploaded correctly. please try again or contact support!."; // if ok, try upload file } else {     if (move_uploaded_file($_files["filetoupload"]["tmp_name"], $target_file)) {         echo "the file". basename( $_files["filetoupload"]["name"]). " has been uploaded.";     } else {         echo "sorry, there error uploading file.";     } } ?> </center> 

why don't use uniqid generate new file name? way sure each file uses unique names.


Comments