现在的位置: 首页 > 综合 > 正文

PHP 文件操作

2013年12月10日 ⁄ 综合 ⁄ 共 2901字 ⁄ 字号 评论关闭

 

 

file_exists, to check whether the file exists

is_file, to check the file is indeed a file and not a directory

is_readable, to check whether the file can be read

is_writable to check whether the file can be written to

filemtime to check the date and time at which the file the file was last modified

fileatime to find the date and time the file at which was last accessed

filesize to check the file’s size

 

 

 

获取文件大小 php

 

 

 

 

 

 

 

1.file() 把整个文件读入一个数组中,数组中的每个单元都是文件中相应的一行,包括换行符在内

eg: file('http://www.dianzhui.net/index.html')

2.file_get_contents() 将整个文件读入一个字符串

3.readfile() 读入一个文件并写入到输出缓冲

4.fopen('file','rb'); fread($fp,filesize('file'));  feof($fp)测试文件指针是否到了文件结束的位置 fgetc($fg)从文件指针中读取字符          fgets($handle[,int $length ])从文件指针中读取一行

   fopen ( string $filename , string $mode [, bool $use_include_path [, resource $zcontext ]] )打开文件或者 URL

   fread( int $handle , int $length ) 读取文件(可安全用于二进制文件)

 

 

 

PHP检测目录

1. opendir() readdir() rewinddir() closedir()

opendir( string $path [, resource $context ] )  打开目录句柄

readdir( resource $dir_handle ) 从目录句柄中读取条目

closedir()

rewinddir() — 倒回目录句柄

eg:

 

 

2.dir — directory 类

    dir::dir ( string $directory )

    string $path ;

resource $handle ;

string read ( void )

void rewind ( void )

void close ( void )

eg:

 

 

 

 

PHP显示屏和平代码

highlight_file ( string $filename [, bool $return = false ] ) 当bool 为true 时,返回字符串,并不是显示

highlight_string(string $str [, bool $return = false ] ) 当bool 为true 时,返回字符串,并不是显示

parse_ini_file( string $filename [, bool $process_sections ] ) — 解析一个配置文件

 

php管理文件下载 『通过特殊的HTTP头和readfile函数』

创建ZIP/TAR文件 用 『pear』类 Archive_Tar 

参考:

http://pear.php.net/package/Archive_Tar/docs/latest/Archive_Tar/Archive_Tar.html

http://pear.php.net/package/Archive_Tar/download/1.3.7/

eg:

 

 

 

 

 

抱歉!评论已关闭.