[Introduction] 1. File upload 1. Client settings: (1) Indicate the corresponding values of the enctype and method attributes in the tag. Enctype= "multipart form-data "; Method= "POST " (2). Set a hidden type input box in the form form, where the value of name is MAX
Terminal settings:
(1). For simple file downloads in
, you only need to use the HTML link tag and specify the downloaded file with the URL value of the href attribute. This method can only handle some MIME type files that the browser cannot recognize.
In order to improve security, if you do not want to give a file link in the a tag, you must send the necessary header information to the browser , we can use the following code.
touch
Set the file access and modification time
bool touch(string $filename[, int $time[, int $time]])
copy
Copy file
bool copy(string $source, string $dest)
Note: To move files, please use the rename function
file_put_contents
Write a string to the file
int file_put_contents(string $filename, string $data[, int $flag[, resource $content]])
file_get_contents
Read the entire file into a string
string file_get_contents(string $filename[, bool user_include_path [, resource $content[, int $ offset[, int $maxlen]]]])
serialize
Serialization
string serialize(mixed $value)
Note: serialize() can handle any type except resouce. You can even serialize() arrays that contain references to themselves.
unserialize
Deserialization
mixed unserialize(string $str)
Format a local time/date
string date(string format[, int timestamp]);
● getdate
Get date/time information
array getdate([int timestamp]);
● microtimestrlenReturns the current Unix timestamp and microseconds
mixed microtime([bool get_as_float]);
● date_default_timezone_set
Set the default time zone
bool date_default_timezone_set(string timezone_identifier);
● date_default_timezone_get
Get the default time zone
string date_default_timezone_get(void);
3. Character function libraryCalculate the MD5 hash of the stringGet the string length
int strlen(string $str);
strtolower
Convert string to lowercase
string strtolower(string $str);
strtoupper
Convert string to uppercase
string strtoupper(string $str);
ucfirst
First letter is capitalized
string ucfirst(string $str);
ucwords
Convert the first letter of each word to uppercase letters
string ucwords(string $str);
ltrim
Remove from the beginning of the string Spaces or other characters
string ltrim(string $str [, string $charlist]);
rtrim
Remove spaces or other characters from the end of the string
string rtrim(string $str[, string $chirlist]);
trim
Remove spaces or other characters from the beginning and end of the string
str_replace
Character replacement
mixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]);
str_ireplace
Character replacement
mixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]);
md5string md5(string $str[, bool $raw_output=false]);
strpos
Returns the position of the first occurrence of one character in another character
int strpos(string haystack, mixed needle[, int offset]);
● date
Format a local time/date
string date(string format[, int timestamp]);
● getdate
Get date/time information
array getdate([int timestamp]);
● microtime
Returns the current Unix timestamp and microseconds
mixed microtime( [bool get_as_float]);
● date_default_timezone_set
Set the default time zone
bool date_default_timezone_set(string timezone_identifier);
● date_default_timezone_get
Get the default time zone
string date_default_timezone_get(void);
3. Character function library
strlen
Get the string length
int strlen(string $str);
strtolower
Convert string to lowercase
string strtolower(string $str);
strtoupper
Convert string to uppercase
string strtoupper(string $str);
ucfirst
First letter is capitalized
string ucfirst(string $str);
ucwords
Convert the first letter of each word to uppercase letters
string ucwords(string $str);
ltrim
Remove spaces or other characters from the beginning of the string
string ltrim(string $str [, string $charlist]);
rtrim
Remove spaces or other characters from the end of the string
string rtrim(string $str[, string $chirlist]);
trim
Start from the string and delete spaces or other characters at the end
str_replace
Character replacement
mixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count] );
str_ireplace
Character replacement
mixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]) ;
md5
Calculate the MD5 hash of the string
string md5(string $str[, bool $raw_output=false]);
strpos
Returns the position of the first occurrence of one character in another character
int strpos(string haystack, mixed needle[, int offset]);
● microtime
Return the current Unix timestamp and microseconds
mixed microtime([bool get_as_float]);
● date_default_timezone_set
Set the default time zone
bool date_default_timezone_set(string timezone_identifier);
● date_default_timezone_get
Get the default time zone
string date_default_timezone_get(void);
strlen
Get the string length
int strlen(string $str);
strtolower
Convert the string to lowercase
string strtolower( string $str);
strtoupper
Convert string to uppercase
string strtoupper(string $str);
ucfirst
Capitalize the first letter of each word
string ucfirst(string $str);
ucwords
Convert the first letter of each word to uppercase letters
string ucwords( string $str);
ltrim
Remove spaces or other characters from the beginning of the string
string ltrim(string $str [, string $charlist]);
rtrim
Remove spaces or other characters from the end of the string
string rtrim(string $str[, string $chirlist]);
trim
Remove spaces or other characters from the beginning and end of the string
str_replace
Character replacement
mixed str_ireplace(mixed $search, mixed $replace , mixed $subject, [int $count]);
str_ireplace
Character replacement
mixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]);
md5
Calculate the MD5 hash of the string
string md5(string $str[, bool $raw_output=false]);
strpos
Return The position where one character first appears in another character
int strpos(string haystack, mixed needle[, int offset]);
1. File upload
1. Client settings:
(1), in
2. File download
Simple file download only needs to use the HTML link tag and specify the downloaded file with the URL value of the href attribute. This method can only handle some MIME type files that the browser cannot recognize.
In order to improve security, if you do not want to give a file link in the a tag, you must send the necessary header information to the browser. We can use the following code .
3. File function library
touch
Setting file Access and modification time
bool touch(string $filename[, int $time[, int $time]])
copy
Copy file
bool copy(string $source, string $dest)
Note: Please use the rename function to move files
file_put_contents
Write a string to the file
int file_put_contents(string $filename, string $data[, int $flag[, resource $content]])
file_get_contents
Read the entire file into the string
string file_get_contents(string $filename[, bool user_include_path [, resource $content[, int $offset[, int $maxlen]]]])
4. Sequence Serialization and deserialization
serialize
Serialization
string serialize(mixed $value)
Note: serialize() Can handle any type except resource. You can even serialize() arrays that contain references to themselves.
unserialize
Deserialization
mixed unserialize(string $str)
● date
Format a local time/date
string date(string format[, int timestamp]);
● getdate
Get date/time information
array getdate([int timestamp]);
##● microtimeReturn the current Unix timestamp and microsecond numbermixed microtime([bool get_as_float]);● date_default_timezone_setSetting Default time zonebool date_default_timezone_set(string timezone_identifier);● date_default_timezone_getGet the default time zonestring date_default_timezone_get(void);3. Character function librarystrlenGet the string lengthint strlen(string $str);strtolowerConvert string to lowercasestring strtolower(string $str);strtoupperConvert string to uppercasestring strtoupper (string $str);ucfirstCapitalize the first letterstring ucfirst(string $str);ucwordswill Convert the first letter of each word to uppercase lettersstring ucwords(string $str);ltrimRemove spaces or other characters from the beginning of the stringstring ltrim(string $str [, string $charlist]);rtrimRemove spaces or other characters from the end of the stringstring rtrim (string $str[, string $chirlist]);trimRemove spaces or other characters from the beginning and end of the stringstr_replaceCharacter replacementmixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]);str_ireplace Character replacementmixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]);md5
Calculate the MD5 hash of the stringstring md5(string $str[, bool $raw_output=false]);strposReturns the position of the first occurrence of one character in another characterint strpos(string haystack, mixed needle[, int offset]);
The above is the detailed content of Upload and download files for PHP mobile Internet development. For more information, please follow other related articles on the PHP Chinese website!