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