PHP uploads instance code and prevents repeated uploads

Source: Internet
Author: User
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 can be used to track the user $ sess_id = session_id (); $ id = rand (subject to cost, 9999999999999999 );******

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.
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"

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.