Home > php教程 > php手册 > body text

批处理和文件系统: php的文件系统处理

WBOY
Release: 2016-06-21 08:49:44
Original
969 people have browsed it

打开文件,处理文件,关闭文件
1打开、关闭文件
is_file($filename)
resource fopen($filename,$mode[,use_include_path)
$filename:可以是绝对路径,也可以是相对路径
$mode是打开的模式,读写。。。等
第三个是是否在服务器的这个路径下打开文件。
关闭文件 
bool fclose(resource handle);
sample:
$f = fopen("a.txt","rb");
fclose($f)
2.读写文件
int readfile($filename)读取整个文件写入到输出缓冲,不需要打开文件,不需要echo,print。
array file($filename) 读取整个文件的内容,按行存储到数组。
file_get_contents($filename,)  将文件读取到一个字符串中
读取一行:
fgets($resource)一次读取一行.如果遇到换行符,EOF,读取到了指定的长度后结束。
fgetss($resource,$length)上面函数的变体,过滤掉html,php标记
读取一个字符
fgetc($resource)
判断是否到文件结束地方
while(!feof($resource))
fread($resource,length) 读取指定长度的数据。
向文件写入数据
fwrite($resource,$string,length)
file_put_contents($filename,$string)
其他文件操作
bool copy($path1,$path2)
bool rename($filename1,$filename2)
bool unlink($filename) 删除文件
array pathinfo($filename)
realpath($filename) 绝对路径

目录函数,目录操作
如果打开一个不存在的文件,就会创建新文件,如果打开一个不存在的额目录就会报错。
打开,关闭目录
resource opendir($path)
@opendir($path)抑制错误输出
closedir($resource) 关闭目录。
is_dir()先判断$path再打开。
浏览目录scandir
array scandir($path)
目录操作
bool mkdir($path)新建一个指定目录
bool rmdir($dirname)删除一个目录,目录必须使空的
string getcwd()获得当前工作目录
bool chdir()改变当前目录为。
高级应用
fopen("http://127.0.0.1/tm/sl/index.php")打开远程文件。。。php配置 allow_url_fopen on
文件指针:
bool rewind($resource) 把文件指针指向到开始处
fseek($resource,$offset,$model)  定位文件指针
bool feof($resource) 判断是否在文件尾  file  end of  file
ftell($resource)报出指针的位置
锁定文件flock($resource,$model)
文件上传
phpini设置,
1是否允许上传文件 file_uploads  on off
2upload_tmp_dir 上传文件的暂时目录
3:upload_max_filesize服务器允许上传的最大值MB为单位
预定义变量#$_FILES
数组第一级键名为name,第二级键名name,size,tmp_name(move_upload_file($sourcefile,$目的文件)),type,error(0表示成功)
多个文件上传,name="name[]"
本文链接http://www.cxybl.com/html/wlbc/Php/20130608/38519.html



Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!