string basename ( string $path [, string $suffix ] ) //给出一个包含有指向一个文件的全路径的字符串,本函数返回基本的文件名。
$path = 'd:/test/test.txt'; echo basename($path); echo "<br>"; echo basename($path,'.txt');
string dirname ( string $path ) //给出一个包含有指向一个文件的全路径的字符串,本函数返回去掉文件名后的目录名。
$path = 'd:/test/test.txt'; echo basename($path); echo "<br>"; echo basename($path,'.txt'); echo "<br>"; echo dirname($path);
mixed pathinfo ( string $path [, int $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME ] ) //pathinfo() 返回一个关联数组包含有 path 的信息。返回关联数组还是字符串取决于 options。
$path = 'd:/test/test.txt'; var_dump(pathinfo($path));
string filetype ( string $filename ) //返回文件的类型。
$path = 'd:/test/test.txt'; echo filetype($path); //结果file
array fstat ( resource $handle ) //获取由文件指针 handle 所打开文件的统计信息。本函数和 stat() 函数相似,除了它是作用于已打开的文件指针而不是文件名。
array stat ( string $filename ) //获取由 filename 指定的文件的统计信息。如果 filename 是符号连接,则统计信息是关于被连接文件本身的,而不是符号连接。 //lstat() 和 stat() 相同,只除了它会返回符号连接的状态。
$path = 'd:/test/test.txt';
$fp = fopen("d:/test/test.txt","r");
$fstat = fstat($fp);
fclose($fp);
var_dump($fstat);
int filesize ( string $filename ) //取得指定文件的大小。
<?php // 输出类似:test.txt: bytes $filename = 'd:/test/test.txt'; echo $filename . ': ' . filesize($filename) . ' bytes'; ?> //结果:d:/test/test.txt: 12 bytes
float disk_free_space ( string $directory ) //给出一个包含有一个目录的字符串,本函数将根据相应的文件系统或磁盘分区返回可用的字节数。
header("Content-Type:Text/html;charset=utf8");
$path = 'd:/test/test.txt';
$df = disk_free_space("d:/");
echo $df."字节";
float disk_total_space ( string $directory ) //给出一个包含有一个目录的字符串,本函数将根据相应的文件系统或磁盘分区返回所有的字节数。 【译者注】本函数返回的是该目录所在的磁盘分区的总大小,因此在给出同一个磁盘分区的不同目录作为参数所得到的结果完全相同。 在 Unix 和 Windows 200x/XP 中都支持将一个磁盘分区加载为一个子目录,这时正确使用本函数就很有意义。
resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] ) //fopen() 将 filename 指定的名字资源绑定到一个流上
| [code]mode[/code] | 说明 |
|---|---|
| [i]'r'[/i] | 只读方式打开,将文件指针指向文件头。 |
| [i]'r+'[/i] | 读写方式打开,将文件指针指向文件头。 |
| [i]'w'[/i] | 写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。 |
| [i]'w+'[/i] | 读写方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。 |
| [i]'a'[/i] | 写入方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。 |
| [i]'a+'[/i] | 读写方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。 |
| [i]'x'[/i] | 创建并以写入方式打开,将文件指针指向文件头。如果文件已存在,则 [b]fopen()[/b] 调用失败并返回 [b][code]FALSE[/code][/b],并生成一条[b][code]E_WARNING[/code][/b] 级别的错误信息。如果文件不存在则尝试创建之。这和给 底层的 [i]open(2)[/i] 系统调用指定 [i]O_EXCL|O_CREAT[/i] 标记是等价的。 |
| [i]'x+'[/i] | 创建并以读写方式打开,其他的行为和 [i]'x'[/i] 一样。 |
<?php
$handle = fopen("/home/rasmus/file.txt", "r");
$handle = fopen("/home/rasmus/file.gif", "wb");
$handle = fopen("http://www.example.com/", "r");
$handle = fopen("ftp://user:password@example.com/somefile.txt", "w");
?>
array file ( string $filename [, int $flags = 0 [, resource $context ]] ) //把整个文件读入一个数组中。
<?php
// 将一个文件读入数组。本例中通过 HTTP 从 URL 中取得 HTML 源文件。
$lines = file('http://www.example.com/');
// 在数组中循环,显示 HTML 的源文件并加上行号。
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
// 另一个例子将 web 页面读入字符串。参见 file_get_contents()。
$html = implode('', file('http://www.example.com/'));
// 从 PHP 5 开始可以使用可选标记参数
$trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>
string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] ) //和 file() 一样,只除了 file_get_contents() 把文件读入一个字符串。将在参数 offset 所指定的位置开始读取长度为 maxlen 的内容。如果失败,file_get_contents() 将返回 FALSE。
header("Content-Type:Text/html;charset=utf8");
// <= PHP 5
$file = file_get_contents('d:/test/test.txt', true);
echo $file.'<br>';
// > PHP 5
$file = file_get_contents('d:/test/test.txt', FILE_USE_INCLUDE_PATH);
echo $file;
//结果
//this is test
//this is test
string fgets ( resource $handle [, int $length ] ) //从文件指针中读取一行。
int ftell ( resource $handle ) //返回由 handle 指定的文件指针的位置,也就是文件流中的偏移量。
header("Content-Type:Text/html;charset=utf8");
// opens a file and read some data
$fp = fopen("d:/test/test.txt", "r");
$data = fgets($fp, 4);
// where are we ?
echo ftell($fp); // 结果3
fclose($fp);
int fseek ( resource $handle , int $offset [, int $whence = SEEK_SET ] ) //在与 handle 关联的文件中设定文件指针位置。 新位置从文件头开始以字节数度量,是以 whence 指定的位置加上 offset。
header("Content-Type:Text/html;charset=utf8");
$fp = fopen('d:\test\test.txt', 'r');
// read some data
$data = fgets($fp, 4096);
// move back to the beginning of the file
// same as rewind($fp);
fseek($fp, 0);
bool flock ( resource $handle , int $operation [, int &$wouldblock ] ) //flock() 允许执行一个简单的可以在任何平台中使用的读取/写入模型(包括大部分的 Unix 派生版和甚至是 Windows)。
if (flock($fp, LOCK_EX)) { // 进行排它型锁定
ftruncate($fp, 0); // truncate file
fwrite($fp, "Write something here\n");
fflush($fp); // flush output before releasing the lock
flock($fp, LOCK_UN); // 释放锁定
} else {
echo "Couldn't get the lock!";
}
fclose($fp);
bool is_readable ( string $filename ) //判断给定文件名是否存在并且可读。
$filename = 'd:\test\test.txt';
if (is_readable($filename)) {
echo 'The file is readable';
} else {
echo 'The file is not readable';
}
//The file is readable
bool is_writable ( string $filename ) //如果文件存在并且可写则返回 TRUE。filename 参数可以是一个允许进行是否可写检查的目录名。
$filename = 'd:\test\test.txt';
if (is_writeable($filename)) {
echo 'The file is writeable';
} else {
echo 'The file is not writeable';
}
//The file is writeable
bool chown ( string $filename , mixed $user ) //尝试将文件 filename 的所有者改成用户 user(由用户名或用户 ID 指定)。 只有超级用户可以改变文件的所有者。
bool is_dir ( string $filename ) //判断给定文件名是否是一个目录。
$filename = 'd:\test\test.txt';
var_dump(is_dir('$filename')); //bool(false)
var_dump(is_dir('d:\test')); //bool(true)
bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )//尝试新建一个由 pathname 指定的目录。
resource opendir ( string $path [, resource $context ] ) //打开一个目录句柄,可用于之后的 closedir(),readdir() 和 rewinddir() 调用中。
string readdir ([ resource $dir_handle ] ) //返回目录中下一个文件的文件名。文件名以在文件系统中的排序返回。
header("Content-Type:Text/html;charset=utf8");
if ($handle = opendir('d:/test')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
/* 这是正确地遍历目录方法 */
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
/* 这是错误地遍历目录的方法
while ($file = readdir($handle)) {
echo "$file\n";
}
*/
closedir($handle);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有