A. Functions
1. Scope (the Scope)
(1) local variables: variables declared valid in the code segment of the
a. dynamic variables
b static variables:. static, used in a function, when the calling function does not release memory, can store the final value of the variable.
(2) global variables: variables are available in any range, but must declare a global variable in a function
global
$GLOBALS
(3) superglobals: variables are valid at any range, and do not declare variables
Note: All predefined variables are superglobals
2. predefined variables
$ _POST: receiving transmission form 'post' information, name / value
$ _GET: receiving transmission form 'get' information, name / value
$ GLOBALS: Global Variables
$ _FILES: receive information in the form of uploading
$ _REQUEST: is equivalent to $ _POST, $ _ GET, $ _ COOKIE accepted
$ _COOKIE: session mechanism, transmitting information across the page
$ _SESSION: session mechanism, transmitting information across the page
$ _SERVER: get server information
$ _ENV: Environment Variables
Description:
a. predefined variables are stored as an array of
For example: the information obtained form one of the values: $ _ POST [ 'user']
print_r ($ _ POST); View all form elements Information
II. Constants
1. What is constant: Once the program can not change the definition of a constant amount can not be redefined
Constant Category 2
(1) Constant Custom
a. declare a constant
(A) define ( 'constant name', 'value');
(B) const constant name = 'value'; (defined in object-oriented)
b. Constant Output
(A) echo constant names;
(B) constant ( 'constant name');
c. Constant Name Authority
(A) no $
(B) the name of the constant capital as much as possible
(C) are constant scalar type
(D) is constant over global variables, in addition to the definition of the outer const
(2) System constants:
a.PHP_INT_MAX obtain maximum integer
b.PHP_VERSION php version
c.PHP_OS operating system
(3) Magic constants:
__LINE__: Get the current line number of code
__FILE__: get the absolute path of the current file
__DIR__: get the absolute path of the current file directory
__FUNCTION__: get the function name
__CLASS__: get the class name
__METHOD__: get method name
__NAMESPACE__: get the name of the namespace
III. Upload
1. Browse box form with conditions
(1) method must be transmitted post
(2) form tag added enctype = "multipart / form-data"
2. Information to accept uploads ($ _FILES array)
(1) $ _FILES [ 'Browse box name'] [ 'name']
Upload file name
(2) $ _FILES [ 'Browse box name'] [ 'type']
Upload file types
(3) $ _FILES [ 'Browse box name'] [ 'tmp_name']
The uploaded file in a temporary directory on the server and the file name
(4) $ _FILES [ 'browse box name'] [ 'error']
Upload file error, 0 for success
(5) $ _FILES [ 'browse box name'] [ 'size']
Upload file size in bytes (Byte)
1024B = 1KB
1024KB = 1MB
1024MB = 1GB
3. File error
(1) UPLOAD_ERR_OK its value is 0, no error occurred, the file uploaded successfully.
(2) UPLOAD_ERR_INI_SIZE a value of 1, the uploaded file exceeds the php.ini upload_max_filesize = 2M limited options.
(3) UPLOAD_ERR_FORM_SIZE a value of 2, upload file size exceeds the value of the HTML form MAX_FILE_SIZE specified options.
(4) UPLOAD_ERR_PARTIAL a value of 3, it was only partially uploaded file.
(5) UPLOAD_ERR_NO_FILE a value of 4, no files are uploaded.
(6) UPLOAD_ERR_NO_TMP_DIR a value of 6, Missing a temporary folder. PHP 4.3.10 and PHP 5.0.3 introduced.
php.ini parameter upload_tmp_dir = 'temporary directory'
(7) UPLOAD_ERR_CANT_WRITE its value is 7, the file writing failure. PHP 5.1.0 introduced.
4. Upload the file to a temporary directory and destination location
move_uploaed_file ($ tmpname, 'Folder' + $ filename);
The functions include file
include: When the file fails to load, newspaper warning (Warning) and back error code continues to execute
require: When the file fails to load, reported fatal (Fatal) Error code behind and stop execution
include_once: When the page loads repeat, loaded only once
require_once: When the page loads repeat, loaded only once
6. Multi-file upload
(1) the name of the form element named in an array,
We have a three-dimensional array of information, so the three-dimensional array into
Two-dimensional array index associated +
(2) form a single element named after give association associated +
Two-dimensional array, so the association + index + into associate associate
The two-dimensional array, with single file upload difference is that there are multiple
Member value
Step 7. Upload
(1) form elements of the browsing condition block comprising
(2) upload the information into accepting the associated two-dimensional array index +
(3) a single file or multiple files to upload
(A) obtain a new index + associated with two-dimensional array (cycles per file upload)
(B) determine the successful upload error 0
(C) avoid conflicts upload files to rename the file
(D) a temporary directory and file name to the target position on
(4) Requirements
...
// =================================
Linux purpose: to www folder permissions
Open a terminal
a. su root (enter the root)
b password:. php123456
c. cd / (root directory)
d. cd home (into the home folder)
e. ll see the home directory resource file www
f. chmod -R 777 www
f. ll