Home  >  Article  >  Backend Development  >  Upload and download files for PHP mobile Internet development

Upload and download files for PHP mobile Internet development

巴扎黑
巴扎黑Original
2017-03-19 09:34:59956browse

[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.


Upload and download files for PHP mobile Internet development

Upload and download files for PHP mobile Internet developmentUpload and download files for PHP mobile Internet development

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.

Upload and download files for PHP mobile Internet development

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)



Upload and download files for PHP mobile Internet development

Upload and download files for PHP mobile Internet development

● date

Format a local time/date

string date(string format[, int timestamp]);

● getdate

Get date/time information

array getdate([int timestamp]);

Upload and download files for PHP mobile Internet development

Upload and download files for PHP mobile Internet development

● 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 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]);

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]);



● date

Format a local time/date

string date(string format[, int timestamp]);

● getdate

Get date/time information

array getdate([int timestamp]);

Upload and download files for PHP mobile Internet development

● 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.


Upload and download files for PHP mobile Internet development

Upload and download files for PHP mobile Internet developmentUpload and download files for PHP mobile Internet development

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 .

Upload and download files for PHP mobile Internet development

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)

Upload and download files for PHP mobile Internet development

Upload and download files for PHP mobile Internet development

● date

Format a local time/date

string date(string format[, int timestamp]);

● getdate

Get date/time information

array getdate([int timestamp]);

Upload and download files for PHP mobile Internet development

Upload and download files for PHP mobile Internet development

##● microtime

Return the current Unix timestamp and microsecond number

mixed microtime([bool get_as_float]);

● date_default_timezone_set

Setting 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

Capitalize the first letter

string ucfirst(string $str);

ucwords

will 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

Returns the position of the first occurrence of one character in another character

int 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn