Php program code for file upload-PHP source code

Source: Internet
Author: User
Tags temporary file storage
This article introduces a simple php program code for file upload for beginners. You can use it for learning. If it is applied on the network, we need more filtering to judge. This article introduces a simple php program code for file upload for beginners. You can use it for learning. If it is applied on the network, we need more filtering to judge.

Script ec (2); script

First look at the instance

The Code is as follows:


// Determine whether the temporary file storage path contains the File Uploaded by the user
If (is_uploaded_file ($ _ FILES ["uploadfile"] ["tmp_name"]) {
// Store information in variables for higher efficiency
$ Upfile = $ _ FILES ["uploadfile"]; // use an array string to store the information of the uploaded file.
// Print_r ($ upfile ); // If printed, the output is similar to this information Array ([name] => m.jpg [type] => image/jpeg [tmp_name] => C: WINDOWSTempphp1A. tmp [error] = & gt; 0 [size] = & gt; 44905)
$ Name = $ upfile ["name"]; // This parameter can be used to transfer files later.
$ Type = $ upfile ["type"]; // File Upload type
$ Size = $ upfile ["size"]; // size of the uploaded file
$ Tmp_name = $ upfile ["tmp_name"]; // temporary name of the file uploaded by the user
$ Error = $ upfile ["error"]; // error message during upload
// Echo $ name;
// Determine the file type to determine whether to transfer the file. If yes, set $ OK = 1 to transfer the file.
Switch ($ type ){
Case "image/jpg": $ OK = 1;
Break;
Case "image/jpeg": $ OK = 1;
Break;
Case "image/gif": $ OK = 1;
Break;
Default: $ OK = 0;
Break;
}
// If the file meets the requirements and there is no error during the upload Process
If ($ OK & $ error = '0 '){
// Call the move_uploaded_file () function for File Transfer
Move_uploaded_file ($ tmp_name, 'Up/'. $ name );
// After the operation is successful, a message is displayed, indicating that the operation is successful.
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.