1. file upload 1. client settings: (1) specify the values of the enctype and method attributes in the tag. Enctype = & quot; multipartform-data & quot; Method = & quot; POST & quot; (2). set an input box of the hidden type in the form, the value of name is MAX.
(1) in
3. PHP file upload and resource commands
File_uploads (boolean)
Whether to enable the http post file upload function
Max_execution_time (integer)
Maximum PHP script execution time
Memory_limit (integer) unit: M
Maximum memory for running PHP scripts
Upload_max_filesize (integer) unit: M
PHP maximum size of uploaded files
Upload_tmp_dir (string)
Temporary Location of uploaded file storage
Post_max_size (integer) unit: M
Maximum size of http post data
4. $ _ FILES array
$ _ FILES ["userfile'] [size]
Obtains the number of bytes of the uploaded file.
$ _ FILES ['userfile'] ['type']
Obtain the MIME type of the uploaded file. each MIME type is composed of the primary and child types separated "/".
$ _ FILES ['userfile'] ['error']
Get the error code of the uploaded file. value 0: no error. the file is successfully uploaded. value 1: The size of the uploaded file exceeds the value specified by the upload_max_filesize option in the PHP configuration file. value 2: the size of the uploaded file exceeds the value specified by MAX_FILE_SIZE in the HTML form. 3: indicates that the file is only partially uploaded; 4: indicates that no file is uploaded.
$ _ FILES ['userfile'] ['name']
Get the original name of the uploaded file, including the extension
$ _ FILES ['userfile'] ['tmp _ name']
Obtain the temporary location name of the uploaded file, which is the file name specified in the temporary directory.
5. file upload function
Is_upload_file
Checks whether the specified file is uploaded through http post.
Bool is_upload_file (string $ filename)
Move_upload_file
Move the uploaded file to a new location
Bool move_upload_file (string $ filename, string $ destination)
Note: after a file is uploaded, it is first stored in the temporary directory of the server. you can use this function to move the uploaded file to a new location. compared with copy () and move, it can detect and ensure that the file specified by the first filename parameter is a legally uploaded file.
6. Error message description
UPLOAD_ERR_ OK {value = 0}
UPLOAD_ERR_INI_SIZE {value = 1}
UPLOAD_ERR_FORM_SIZE {value = 2}
UPLOAD_ERR_PARTIAL {value = 3}
UPLOAD_ERR_NO_FILE {value = 4}
UPLOAD_ERR_NO_TMP_DIR {value = 6}
UPLOAD_ERR_CANT_WRITE {value = 7}
II. file download
To download a simple file, you only need to mark the HTML link and specify the URL value of the href attribute to the downloaded file. This method can only process MIME-type files that cannot be recognized by some browsers.
FileHttp://blog.csdn.net/dawanganban/article/details/php.zipfile download
To improve security, if you do not want to provide a file link in tag a, you must send necessary header information to the browser. we can use the following code.
III. file function library
Touch
Set file access and modification time
Bool touch (string $ filename [, int $ time [, int $ time])
Copy
Copy a file
Bool copy (string $ source, string $ dest)
Note: Use the rename function to move files.
File_put_contents
Write a string to a file
Int file_put_contents (string $ filename, string $ data [, int $ flag [, resource $ content])
File_get_contents
Read the entire file to a string
String file_get_contents (string $ filename [, bool user_include_path [, resource $ content [, int $ offset [, int $ maxlen])
IV. serialization and deserialization
Serialize
Serialization
String serialize (mixed $ value)
Note: serialize () can process any type except resouce. Even serialize () contains arrays that point to its own reference.
Unserialize
Deserialization
Mixed unserialize (string $ str)
'; Var_dump ($ arr); echo'
'; // Deserialization echo' deserialization
'; $ Arr1 = unserialize ($ arr); var_dump ($ arr1); echo'
';?>