P 2026-11-06 PHP feof() 函数 定义和用法 feof() 函数检查是否已到达文件末尾(EOF)。 如果出错或者文件指针到了文件末尾(EOF)则返回 TRUE,否则返回 FALSE。 语法 feof(file) 参数 描述 file 必需。规定要检查的打开文件。 提示和注释 提示: feof() 函数对遍历长度未知的数据很有用。 实例 <?php $file = fopen("test.txt", "r"); //Output a line of the file until the end is reached while(! feof($file)) { echo fgets($file). "<br />"; } fclose($file); ?> 上面的代码将输出: Hello, this is a test file. There are three lines here. This is the last line.
阅读全文 ↗ P 2026-11-06 PHP fclose() 函数 定义和用法 fclose() 函数关闭打开的文件。 该函数如果成功则返回 TRUE,如果失败则返回 FALSE。 语法 fclose(file) 参数 描述 file 必需。规定要关闭的文件。 实例 <?php $file = fopen("test.txt","r"); //some code to be executed fclose($file); ?>
阅读全文 ↗ P 2026-11-06 PHP diskfreespace() 函数 定义和用法 diskfreespace() 函数返回指定目录的可用空间,以字节为单位。 该函数是 disk_free_space() 函数的别名。 语法 diskfreespace(directory) 参数 描述 directory 必需。规定要检查的目录。 实例 <?php echo diskfreespace("C:"); ?> 上面的代码将输出: 109693288448
阅读全文 ↗ P 2026-11-06 PHP disk_total_space() 函数 定义和用法 disk_total_space() 函数返回指定目录的磁盘总容量,以字节为单位。 语法 disk_total_space(directory) 参数 描述 directory 必需。规定要检查的目录。 实例 <?php echo disk_total_space("C:"); ?> 上面的代码将输出: 119990349824
阅读全文 ↗ P 2026-11-06 PHP disk_free_space() 函数 定义和用法 disk_free_space() 函数返回指定目录的可用空间,以字节为单位。 语法 disk_free_space(directory) 参数 描述 directory 必需。规定要检查的目录。 实例 <?php echo disk_free_space("C:"); ?> 上面的代码将输出: 109693288448
阅读全文 ↗ P 2026-11-06 PHP dirname() 函数 定义和用法 dirname() 函数返回路径中的目录名称部分。 语法 dirname(path) 参数 描述 path 必需。规定要检查的路径。 实例 <?php echo dirname("c:/testweb/home.php") . "<br />"; echo dirname("/testweb/home.php"); ?> 上面的代码将输出: c:/testweb /testweb
阅读全文 ↗ P 2026-11-06 PHP copy() 函数 定义和用法 copy() 函数复制文件。 该函数如果成功则返回 TRUE,如果失败则返回 FALSE。 语法 copy(file,to_file) 参数 描述 file 必需。规定要复制的文件。 to_file 必需。规定复制文件的目的地。 提示和注释 注释: 如果目标文件已存在,将会被覆盖。 实例 <?php echo copy("source.txt","target.txt"); ?> 上面的代码将输出: 1
阅读全文 ↗ P 2026-11-06 PHP clearstatcache() 函数 定义和用法 clearstatcache() 函数清除文件状态缓存。 PHP会缓存某些函数的返回信息,以便提供更高的性能。但是有时候,比如在一个脚本中多次检查同一个文件,而该文件在此脚本执行期间有被删除或修改的危险时,你需要清除文件状态缓存,以便获得正确的结果。要做到这一点,请使用clearstatcache() 函数。 语法 clearstatcache() 提示和注释 提示: 会进行缓存的函数,即受 clearstatcache() 函数影响的函数: stat() lstat() file_exists() is_writable() is_readable() is_executable() is_file() is_dir() is_link() filectime() fileatime() filemtime() fileinode() filegroup() fileowner() filesize() filetype() fileperms() 实例 <?php //check filesize echo filesize("test.txt"); echo "<br />"; $file = fopen("test.txt", "a+"); // truncate file ftruncate($file,100); fclose($file); //Clear cache and check filesize again clearstatcache(); echo filesize("test.txt"); ?> 上面的代码将输出: 792 100
阅读全文 ↗ P 2026-11-06 PHP chown() 函数 定义和用法 chown() 函数改变指定文件的所有者。 如果成功则返回 TRUE,如果失败则返回 FALSE。 语法 chown(file,owner) 参数 描述 file 必需。规定要检查的文件。 owner 必需。规定新的所有者。可以是用户名或用户的 ID。 实例 <?php chown("test.txt","charles") ?>
阅读全文 ↗ P 2026-11-06 PHP chmod() 函数 定义和用法 chmod() 函数改变指定文件的权限。 如果成功则返回 TRUE,如果失败则返回 FALSE。 语法 chmod(file,mode) 参数 描述 file 必需。规定要检查的文件。 mode 必需。规定新的权限。 mode 参数由 4 个数字组成: * 第一个数字通常是 0 * 第二个数字规定所有者的权限 * 第三个数字规定所有者所属的用户组的权限 * 第四个数字规定其他所有人的权限 可能的值(如需设置多个权限,请对下面的数字进行总计): * 1 = 执行权限 * 2 = 写权限 * 4 = 读权限 实例 <?php // Read and write for owner, nothing for everybody else chmod("test.txt",0600); // Read and write for owner, read for everybody else chmod("test.txt",0644); // Everything for owner, read and execute for everybody else chmod("test.txt",0755); // Everything for owner, read for owner's group chmod("test.txt",0740); ?>
阅读全文 ↗ P 2026-11-06 PHP chgrp() 函数 定义和用法 chgrp() 函数改变指定文件的用户组。 如果成功则返回 TRUE,如果失败则返回 FALSE。 语法 chgrp(file,group) 参数 描述 file 必需。规定要检查的文件。 group 可选。规定新的组。可以是组名或组的 ID。 实例 <?php chgrp("test.txt","admin") ?>
阅读全文 ↗ P 2026-11-06 PHP basename() 函数 定义和用法 basename() 函数返回路径中的文件名部分。 语法 basename(path,suffix) 参数 描述 path 必需。规定要检查的路径。 suffix 可选。规定文件扩展名。如果文件有名有文件扩展名,将不会显示这个扩展名。 实例 <?php $path = "/testweb/home.php"; //Show filename with file extension echo basename($path) ."<br/>"; //Show filename without file extension echo basename($path,".php"); ?> 上面的代码将输出: home.php home
阅读全文 ↗