PHP upload Instance code to prevent duplicate upload, this upload instance code is very suitable for PHP novice learning, there are detailed comments.
Session_Start ();
/****** The following can be used to track users
$sess _id = session_id ();
$id = rand (100000000000000,9999999999999999);
******/
if ($_post["Submit"]) {
/****** the following is to prevent duplicate uploads, applicable to only allow uploading once
if ($_session["name"] = = "1") {
echo "
Please do not repeat the submission!
";
Exit
}
******/
$file _name = $_files["File" ["Name"];
$file _size = $_files["File" ["Size"];
$file _type = $_files["File" ["type"];
$file _tn = time (). $file _name;
$save _path = "upfiles/";
$MESSG = "
Uploading files outside of the event:
return to retry ";
$MESSG _sr = $MESSG;
if ($file _type! = "Application/msword") {//Breeze hint, here limit upload format to Word
$MESSG. = "
This upload file format is Ms WORD, usually with a. doc extension.
";
}
if ($file _size > 1048576) {//Breeze hint, this can be written as "if ($file _size > 1*1024*1024) {" For easy modification
$MESSG. = "
This upload file size cannot exceed 1MB, this file size is ". Round (($file _size/1024/1024), 2)." MB
";
}
if ($MESSG! = $MESSG _sr) {
Echo $MESSG;
}else{
if (Move_uploaded_file ($_files["file"] ["Tmp_name"], $save _path. $file _tn)) {
$_session["name"] = "1"; #防止重复上传和上面对应
Here are the various tips and jumps for successful uploads
echo "
Congratulations to you! Upload file successfully.
";
echo "";
echo "";
echo " "; #原型
echo " Upload success! ";
}else{
Echo $MESSG;
}
}
}else{
?>
<title>File Upload</title>
http://www.bkjia.com/PHPjc/486531.html www.bkjia.com true http://www.bkjia.com/PHPjc/486531.html techarticle PHP Upload Instance code to prevent duplicate upload, this upload instance code is very suitable for PHP novice learning, there are detailed comments. PHP session_start ();/****** The following can be used to track user $sess _i ...