PHP uploads the instance code and prevents repeated uploads. PHP uploads the instance code to prevent repeated uploads. this Upload instance code is very suitable for beginners of php to learn and has detailed annotations .? Phpsession_start (); ****** the following code can be used to track user $ sess_ I PHP to upload instance code to prevent repeated uploads. this Upload instance code is very suitable for php beginners to learn and has detailed annotations.
Session_start ();
/****** The following can be used to track users:
Else $ sess_id = session_id ();
Between $ id = rand (between 0000000000,9999999999999999 );
******/
If (commit $ _ POST ["Submit"]) {
/****** The following is to prevent repeated uploads, which is applicable only once.
If (response $ _ SESSION ["name"] = "1 "){
Echo"
Please do not submit it again!
";
Exit;
}
******/
Program $ file_name = program $ _ FILES ["file"] ["name"];
Objects $ file_size = objects $ _ FILES ["file"] ["size"];
Parameters $ file_type = parameters $ _ FILES ["file"] ["type"];
Consumed $ file_tn = time (). consumed $ file_name;
Optional $ save_path = "upfiles /";
Required $ messg ="
In addition to uploading files:
Return retry ";
Required $ messg_sr = required $ messg;
If (bytes $ file_type! = "Application/msword") {// breeze prompt, the upload format is limited to word
Parameters $ messg. ="
The file to be uploaded is in the format of MS word, and the common extension name is .doc.
";
}
If (response $ file_size> 1048576) {// breeze prompt, which can be written as "if (response $ file_size> 1*1024*1024) {" easy to modify
Parameters $ messg. ="
The size of the uploaded file cannot exceed 1 MB. The size of this file is ". round (bytes $ file_size/1024/1024), 2)." MB
";
}
If (else $ messg! = Orders $ messg_sr ){
Echo done $ messg;
} Else {
If (move_uploaded_file (packages $ _ FILES ["file"] ["tmp_name"], packages $ save_path. packages $ file_tn )){
// Resume $ _ SESSION ["name"] = "1"; # prevent repeated uploads from matching the above
// The following are the prompts and jumps for successful uploads:
// Echo"
Congratulations! The file is uploaded successfully.
";
// Echo"