一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

移动网站开发教程五,php上传下载文件

时间:2014-12-22 编辑:简简单单 来源:一聚教程网

一、文件的上传

1、客户端设置:

(1)、在

标签中将enctype和method两个属性指明相应的值。

Enctype="multipart/form-data"; Method="POST"

(2)、form表单中设置一个hidden类型的input框,其中name的值为MAX_FILE_SIZE的隐藏值

2、服务器端设置:

(1)、$_FILES多维数组:用于存储各种上传文件有关的信息

(2)、文件上传php配置文件的设置,如以下php.ini文件中的一些指令

指令 默认值 功能描述

file_uploads ON 确定服务器上的PHP脚本是否可以接受HTTP文件上传

memory_limit 8M 设置脚本可以分配的最大内存量,防止失控的脚本独占服务器内存

upload_max_file 2M 限制PHP处理上传文件大小的最大值,此值必须小于POST_MAX_SIZE值

post_max_size 8M 限制通过POST方法可以接受信息的最大值

upload_tmp_dir NULL 上传文件的临时路径,可以是一个绝对路径

 

移动网站开发教程五,php上传下载文件

 

 

移动网站开发教程五,php上传下载文件

 

 

移动网站开发教程五,php上传下载文件

 

 

移动网站开发教程五,php上传下载文件

 

三、文件函数库

touch

设置文件的访问和修饰时间

bool touch(string $filename[, int $time[, int $time]])

copy

复制文件

bool copy(string $source, string $dest)

注意:移动文件请使用rename函数

file_put_contents

将一个字符串写入文件

int file_put_contents(string $filename, string $data[, int $flag[, resource $content]])

file_get_contents

将整个文件读到字符串

string file_get_contents(string $filename[, bool user_include_path [, resource $content[, int $offset[, int $maxlen]]]])

四、序列化与反序列化

serialize

序列化

string serialize(mixed $value)

注意:serialize()可处理除了resouce之外的任何类型。甚至可以serialize()那些包含了指向其自身引用的数组。

unserialize

反序列化

mixed unserialize(string $str)

 

移动网站开发教程五,php上传下载文件

 

 

移动网站开发教程五,php上传下载文件

 

 

移动网站开发教程五,php上传下载文件

 

● microtime

返回当前Unix时间戳和微秒数

mixed microtime([bool get_as_float]);

● date_default_timezone_set

设置默认时区

bool date_default_timezone_set(string timezone_identifier);

● date_default_timezone_get

获取默认时区

string date_default_timezone_get(void);

三、字符函数库

strlen

获取字符串长度

int strlen(string $str);

strtolower

字符串转换为小写

string strtolower(string $str);

strtoupper

字符串转换为大写

string strtoupper(string $str);

ucfirst

首字母大写

string ucfirst(string $str);

ucwords

将每个单词的首字母转换为大写字母

string ucwords(string $str);

ltrim

从字符串开始的位置删除空格或其他字符

string ltrim(string $str [, string $charlist]);

rtrim

从字符串结束的位置删除空格或者其他字符

string rtrim(string $str[, string $chirlist]);

trim

从字符串开始和结束的位置删除空格或者其他字符

str_replace

字符替换

mixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]);

str_ireplace

字符替换

mixed str_ireplace(mixed $search, mixed $replace, mixed $subject, [int $count]);

md5

计算字符串的MD5哈希

string md5(string $str[, bool $raw_output=false]);

strpos

返回一个字符在另一个字符第一次出现的位置

int strpos(string haystack, mixed needle[, int offset]);

热门栏目