Home  >  Article  >  Backend Development  >  文件操作函数_PHP

文件操作函数_PHP

WBOY
WBOYOriginal
2016-06-01 12:39:48964browse

PHP3.0中的文件操作函数大体和C的类似,但有一些扩充,特别是除了支持

对本机文件的访问外,也支持对HTTP和FTP的URL进行访问,只要把这些URL作为文件名传递给文件操作函数就可以了.

主要的文件操作函数有:

(1)fclose, feof, fgetc, fgets, fopen, fputs, fseek, ftell, mkdir, readlink, rename, rewind, rmdir, stat, unlink

这些函数的功能和C语言中的同名函数类似.

 

(2)chgrp, chmod, chown, copy

这些函数的含义也都很容易理解:

chgrp(文件名,组);

chmod(文件名,模式);

chown(文件名,用户);

copy(源文件名,目标文件名);

需要注意的是:这些函数用的是文件名而不是fopen返回的文件号.

 

(3)file_exists, fileatime, filectime, filegroup, fileinode, filemtime, fileowner, filesize, filetype, fileperms, fileumask, is_dir, is_executable, is_file, is_link, is_readable, is_writeable

这些是文件信息函数,大多接受一个文件名作为参数.

 

(4)fgetss

用法:

fgetss(文件号,最大长度);

读取文件的一行或直到最大长度(类似于fgets),但去掉所有的 HTML和PHP标记.

 

(5)file

用法:

file(文件名);

返回一个数组,每一个元素是文件中的一行.

 

(6)tempnam

用法:

tempnam(目录名,前缀);

返回一个临时文件名.

 

(7)basename, dirname

取得文件路径中的文件名部分和目录名部分. 在Windows系统下,"/"和"\"都可以作为目录分割符,其他系统下只有"/"可以.


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
Previous article:为加速PHP程序而努力_PHPNext article:默认值_PHP