php - Upload file and rename before saving -


i obtained code w3school upload files server, how can change file name random number there wont issues of duplication. can please assist in showing me correct , safest way upload files.

// change folder permission files can uploaded     chmod('_data/cvs/', 0777);      // upload file server     $target_dir = "_data/cvs/";     $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 image - " . $check["mime"] . ".";             $uploadok = 1;         } else {             echo "file not image.";             $uploadok = 0;         }     }         // check if file exists         if (file_exists($target_file)) {             echo "sorry, file exists.";             $uploadok = 0;         }         // check file size         if ($_files["filetoupload"]["size"] > 500000) {             echo "sorry, file large.";             $uploadok = 0;         }         // allow file formats         if($imagefiletype != "doc" && $imagefiletype != "docs" && $imagefiletype != "pdf"         && $imagefiletype != "gif" ) {             echo "sorry, doc, docs , pdf files allowed.";             $uploadok = 0;         }         // check if $uploadok set 0 error         if ($uploadok == 0) {             echo "sorry, file not uploaded.";         // 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.";             }         }      // change folder permission nothing can uploaded     chmod('_data/cvs/', 0644); 

thanks in advance!

what use time() function.

i change part of code:

$target_file = $target_dir .time(). basename($_files["filetoupload"]["name"]); 

Comments

Popular posts from this blog

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -