php常用的文件操作函数参考表_PHP教程

WBOY
Freigeben: 2016-07-20 11:02:23
Original
874 Leute haben es durchsucht

 

不断阅读,你就会发现一些新内容!

表a

函数

说明

实例

filesize

($file)

此函数以字节为单位返回一个文件的大小。它用于计算一个文件在磁盘上占有多少空间。

// get file owner and group
echo "uid: " . fileowner('myfile.html');
echo "gid: " . filegroup('myfile.html');
?>

fileatime

($file)

filemtime

($file)

这些函数分别返回某一文件最后被访问及修改的时间,用于找出一个文件在一个特定的日期后是否被修改。

// get file access/modification times
echo "last accessed on: " . date("d-m-y", fileatime('myfile.html'));
 
echo "last modified on: " . date("d-m-y", filemtime('myfile.html'));
?>

fileperms

($file)

此函数返回一个文件许可,用它来检查文件是否可读,可写或可执行。

// get permissions in octal format
echo "file permissions: " . sprintf('%0', fileperms('myfile.html'));
?>

filetype

($file)

此函数返回文件的“类型”—是否连接,目录,特性或块设备,或常规文件。在执行某项操作前,用它来检验文件的本质。

// get file type
echo "file type: " . filetype('myfile.html');
?>

stat($file)

这是一个“包罗万象”的函数,它返回一个文件的详细统计资料,包括它的所有者与所属组,大小,最后修改时间,索引节点数目。如果你需要在一个单独的函数调用中获得全面的文件统计资料,请使用此函数而不是前面列举的那些函数。

// get file statistics
print_r(stat('myfile.html'));
?>

realpath

($file)

此函数将一个相对文件路径转换为绝对文件路径,当需要找出一个文件在磁盘上的准确位置,则使用此函数。

// get absolute path
// returns "/tmp/myfile.html"
echo "file path: " . realpath("./cook/book/http://www.cnblogs.com/myfile.html");
?>

basename

($file)

dirname

($file)

只要给定一个完整的文件路径,这些函数就能将其分解为各个组成部分,并分别返回文件名和目录。

// split directory and file names
// returns "/usr/local/bin"
echo "directory: " . dirname("/usr/local/bin/php");
 
// returns "php"
echo "file: " . basename("/usr/local/bin/php");
?>

file($file)

此函数将一文件的内容读入一数组。数组中的每一个元素代表一行文件。此函数用于将文件内容读入一个变量中,以便对它进行进一步的加工。

// read file contents
$lines = file('myfile.html');
 
// print line by line
for($x=1; $x ?echo "line $x: " . $lines[$x-1] . "n";
}
?>


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445360.htmlTechArticle不断阅读,你就会发现一些新内容! 表a 函数 说明 实例 filesize ($file) 此函数以字节为单位返回一个文件的大小。它用于计算一个文件在磁...
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!