Knowledge Point; 1. User-defined functions 2. File upload and download 1. User-Defined Function: return type function name (parameter type $ val, parameter type $ val, parameter type $ val ...) system function; mathstringdatearraystringtrim ($ str) substrstrposstr_replace ...... returns the object name extension function.
Knowledge Point; 1. User-defined functions 2. File upload and download 1. User-Defined Function: return type function name (parameter type $ val, parameter type $ val, parameter type $ val ...) system function; math string date array string trim ($ str) substr strpos str_replace ...... returns the object name extension function.
Knowledge Point;
I. User-Defined Functions
Ii. File upload and download
I. User-Defined Functions
Function:
Return Value Type Function Name (parameter type $ val, parameter type $ val, parameter type $ val ...)
System functions;
Math
String
Date
Array
String
Trim ($ str)
Substr
Strpos
Str_replace
......
Returns the object name extension function.
$ F1 = "mysql. class. php ";
// $ ExtName = end (explode (".", $ f1 ));
$ En = gt ($ f1 );
$ F2 = "index. php ";
// $ ExtName2 = end (explode (".", $ f2 ));
$ En2 = gt ($ f2 );
Function: used repeatedly. Easy to manage, efficient, fast, and tidy code.
1. Custom functions:
User-defined functions.
1. Basic user-defined functions:
Function Name (){
Function body.
}
When a function is written to a page, it is not executed immediately,
The function is executed only when the function is called.
Call: function name ();
Return Value Type Function Name (parameter type ....)
Void adds (void)
// Exercise:
Function: from 1 + ----- 10
AddTen ()
2. There are parameters that do not return values.
Function Name (parameter type parameter 1, parameter type parameter 2 ,....){
Function body;
}
Assign values when calling
// Print the extension for any file name.
Note:
In a function, the content is changeable (any) and is set as a parameter.
Application: the default value can be set for the parameter.
Default: If a parameter is passed, the function uses the parameter to work.
If no parameter exists, the function uses the default value.
The default value is required.
The default null value of the string.
Integer: 0
Boolean true
3. parameters have returned values.
Function Name (parameter type $ val ,.....){
Function body;
Return value; // pass the result of the function operation to the outside.
}
Returned value: When a function is called,
The result of the function execution. The result can be used outside.
Function exercise:
Note: All codes can be encapsulated into functions.
Including html css p php
Array: An array can be used as a parameter or return value.
File Size Determination: function for determining the size of a file. 2000
Question: Why is the following Code 123;
$ Test = 123;
Function changeNum (){
$ Test = 456;
}
ChangeNum ();
Echo $ test;
Recursive Function: Calls itself internally. Call yourself.
There must be an end condition.
1 ++ 5
$ Sum = 0;
For ($ I = 0; $ I <= 5; $ I ++ ){
$ Sum = $ sum + $ I;
}
Start Condition
Conditions for termination
Loop body
Renewal duration
$ Sum = 0;
For ($ I = 5; $ I >=0; $ I --){
$ Sum = $ sum + $ I;
}
// 1 + + + 5 5 + 4 + 3 + 2 + 1 + 0 termination conditions
Function sum ($ n) {// $ n = 5
If ($ n = 1 ){
Return 1;
} Else {
Return $ n + sum ($ N-1)
}
}
Return 5 + 10
Return 4 + 6
Return 3 + 3
Return 3
Return 1
Function: A piece of code is used in multiple places.
Function library:
Func_get_arg ();
Purpose: return the parameter value at the corresponding position. The position starts from 0.
Format: mixed func_get_arg (int $ arg_num)
Func_get_args ();
Purpose: return an array composed of parameters and an index array.
Format: array func_get_args (void)
Func_num_args ();
Purpose: return the number of parameters.
Format: int func_num_args (void)
Function_exists ()
Purpose: judge whether a function exists. If yes, true does not exist. false
Format: bool function_exists (string $ function_name)
Ii. File upload and download
1. Upload: upload images and attachments.
Form:
Action = "" specifies the path to the page for processing submitted data
Method = "get | post"
Index --- "indexDo
Get ---> url 2 k path pass value form method = "get"
Post ---> http post 8 M form method = "post" by default"
Aaaa
The id will be passed to indexDo together with the aaaa hyperlink.
The path value passing method must be get.
Get post *******
The size of the passed Value
The get url value is displayed in the url, which is less secure.
Post is more secure.
Form
Index ----> method = post ---> indexDo
Receive data:
$ _ POST ["name attribute of the control"]
Index ----> method = get ---> indexDo
$ _ GET ["Control name attribute"]
A
IndexDo. php? Id = 456
$ _ GET ["id"]
2. File Upload:
1. enctype = "multipart/form-data"
Encodetype Encoding
Method = "post"
Image Upload control type = "file" $ _ FILES ["Control name"]
Array
(
[Name] => 1.jpg
[Type] => image/pjpeg
[Tmp_name] => C: \ WINDOWS \ Temp \ php80F. tmp
[Error] => 0
[Size] = & gt; 9825 bytes
1 k = 1000 bytes 1 M = 1000 k 1 m = 2000000
)
Move_uploaded_file (temporary location, specified path)
Exit; terminate subsequent program execution.
3. Steps for uploading images:
1. determine the format extension of the image.
2. Determine the image size in bytes $ userImg ["size.
3. Rename the file and upload it.
4. Other File Upload knowledge
Array
(
[Name] => 1.jpg file name
[Type] => image/pjpeg mime type
[Tmp_name] => C: \ WINDOWS \ Temp \ php80F. tmp temporary location.
[Error] => 0 file error message
[Size] => 9825 bytes File size
1 k = 1000 bytes 1 M = 1000 k 1 m = 2000000
)
[Error] => 0 file error message
0 files uploaded successfully
1 File Upload upload_max_filesize = 2 M File Upload maximum transfer data volume
Post_max_size = 8 M
2. Understanding
3. A network problem occurs during the upload and the file has not been transferred.
4. No file is selected for upload.
Is_uploaded_file method = "post"
Index ---> indexDo
Is_uploaded_file: checks whether the data is http post.
5. File Download
1. Hyperlinks can be used. Only browsers can be used as file doc. exe rar.
The browser can recognize: Open it directly.
2. Common download methods:
// Set the file to download this part of the application
Header ("Content-type: application/x-msdownload ");
// The download dialog box is displayed.
Header ("Content-Disposition: attachment?filename=demo.jpg ");
// Download
Readfile('1.jpg ');
Thank you for following the websites blog!