PHP File Upload simple instance code-PHP source code

Source: Internet
Author: User
This article provides you with a simple php file upload function code. If you are a beginner of php, this file upload code is easy to understand and can be used as an example. This article provides you with a simple php file upload function code. If you are a beginner of php, this file upload code is easy to understand and can be used as an example.

Script ec (2); script

If ($ _ FILES ['file']) {
// Outputs //----------------------------------------------------------------------------------------------//
//
// Description: File Upload Date: 2004-5-2
//
// Outputs //----------------------------------------------------------------------------------------------//


// Upload settings
$ Maxsize = 10002400; // maximum file size that can be uploaded
$ Alltype = array (". php", ". php3"); // all file types that can be uploaded
$ Imgtype = array (". php", ". php3"); // type

// Determine the file size
If ($ _ FILES ['file'] ['SIZE']> $ maxsize ){
Echo "the information you uploaded exceeds 10000 kb ";
Exit;
}

// Determine the file type
$ Type = strstr ($ _ FILES ['file'] ['name'], ".");
If (in_array ($ type, $ alltype )){
Echo "this type of file cannot be uploaded ";
Exit;
}
Include './uploaddir. php ';
$ Time = date ("Ymd-His", time ());
$ Fn = $ time. $ type;
$ Destination = $ updir. "/". $ fn;
If (@ move_uploaded_file ($ _ FILES ['file'] ['tmp _ name'], $ destination )){
@ Chmod ($ destination, 0777 );
$ Fileurl = $ updir. "/". $ destination;
$ Fileurl = "". $ destination;

} Else {
Echo "Upload Failed! ";
Echo "script location. href = history. back () script";
}
// Outputs //----------------------------------------------------------------------------------------------//
}
If ($ back = "no "):
Echo "OK ";
Exit;
Endif;
?>


Upload files

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.