PHP upload Instance code and prevent duplicate uploads _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.