PHP mobile Internet Development notes (5)-upload and download files,
Address: http://www.php100.com/html/php/rumen/2014/0326/6706.html
I. File Upload
1. Client settings:
(1) In
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.
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)
● 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 the number of microseconds.
Mixed microtime ([bool get_as_float]);
● Date_default_timezone_set
Set Default Time Zone
Bool date_default_timezone_set (string timezone_identifier );
● Date_default_timezone_get
Get Default Time Zone
String date_default_timezone_get (void );
Iii. Character function library
Strlen
Returns the string length.
Int strlen (string $ str );
Strtolower
String to lowercase
String strtolower (string $ str );
Strtoupper
Convert string to uppercase
String strtoupper (string $ str );
Ucfirst
Uppercase letters
String ucfirst (string $ str );
Ucwords
Converts the first letter of each word to an uppercase letter.
String ucwords (string $ str );
Ltrim
Removes spaces or other characters from the start of a string.
String ltrim (string $ str [, string $ charlist]);
Rtrim
Removes spaces or other characters from the end of a string.
String rtrim (string $ str [, string $ chirlist]);
Trim
Removes spaces or other characters from the start and end of a 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 a string
String md5 (string $ str [, bool $ raw_output = false]);
Strpos
Returns the position where one character appears for the first time.
Int strpos (string haystack, mixed needle [, int offset]);