In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you the php file upload example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
First, my preparation is explained.
Editor: sublime text3 (what editor do you use to see what you like)
Server build: build the server using phpstudy2014, and the server files are stored in the www file on my own computer's D disk. Installing phpstudy automatically generates www files, and you can choose which disk to install on your own. Run phpstudy and you can access the files in the server by entering localhost in the browser address bar.
The process of uploading a file: the browser uploads the file on the client, clicks submit, and the file is sent to a php file in the server for processing, and the php saves the uploaded file to the server.
Create a form
Please look at my html code
Enctype
In the syntax of the Form element, EncType indicates that the format of the submitted data uses the Enctype attribute to specify the type of encoding used by the browser when the data is posted back to the server. There are three types of enctype:
1. Application/x-www-form-urlencoded: form data is encoded as name / value pairs. This is the standard coding format.
2. Multipart/form-data: the form data is encoded as a message, and each control on the page corresponds to a part of the message.
3. Text/plain: form data is encoded in plain text and does not contain any controls or format characters.
Add (just look around): the enctype attribute of orm is encoded, which is commonly used in two ways: application/x-www-form-urlencoded and multipart/form-data. The default is application/x-www-form-urlencoded. When action is get, the browser uses x-www-form-urlencoded encoding to convert the form data into a string (name1=value1&name2=value2. ), and then append the string after url, using? Split and load the new url. When action is post, the browser encapsulates the form data into http body and sends it to server. If you don't have type=file controls, you can use the default application/x-www-form-urlencoded. But if you have type=file, you need to use multipart/form-data. The browser divides the entire form into controls and adds information such as Content-Disposition (form-data or file), Content-Type (default to text/plain), name (control name) to each section, and adds a separator (boundary).
It's a little hard to understand.
Always remember two words: if there is a type=file in the input tag, then enctype=multipart/form-data. If there is no type=file, generally use application/x-www-form-urlencoded.
When a file is uploaded, the data must be converted before it can be uploaded to the server. The difference between application/x-www-form-urlencoded and multipart/form-data is different from the conversion coding method.
Third, create php files to process uploaded files.
The effect after uploading the file is as follows:
Each uploaded file has name, type, size, tmp_name and other information. After the file is uploaded, the information related to the file exists in the array variable FILES. _ FILES ["myfile"] ["name"] is equivalent to the access of a multi-dimensional array. FILES first obtains the file data uploaded by input with the form name myfile, and then accesses name, type, size, error, and so on. _ FILES ["myfile"] ["error"] is used to handle situations where files are not uploaded normally, such as exceeding the limit for uploading files. If FILES ["myfile"] ["error"] = 0, the file is uploaded normally. _ FILES ["myfile"] ["error"] > 0 means that the file has not been uploaded normally.
FILES ["myfile"] ["error"] = 1 uploading files exceeds the server limit, such as the size of server space. _ FILES ["myfile"] ["error"] = 2 exceeds the browser limit upload value $_ FILES ["myfile"] ["error"] = 3 only part of the file is uploaded
FILES ["myfile"] ["error"] = 4 No file is uploaded. _ FILES ["myfile"] ["error"] can also be 5, 6, 7, 8. Don't dig into it here, just know that if it's greater than 0, it means an error was uploaded to the file.
Upload limit
In general, the server usually limits the size or type of files uploaded by the server. We add restrictions on uploading file code based on the above php code.
First, be familiar with the usage of a few functions:
The explode () function is used to split a string, for example: explode (".", "aaa.HTML") divides the string into "aaa" and "HTML" strings at the point, which are stored sequentially in the same array.
End () gets the value of the last element in the array.
In_array () looks for an element in the array to see if it exists, which returns true and none returns false.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.