无需言 做自己 业 ,精于勤 荒于嬉.

文件系统函数 realpath_cache_size 获取真实路径缓冲区的大小

发表日期:2021-07-01 08:55:44 | 来源: | 分类:文件系统函数

      示例1
<?php 
var_dump(realpath_cache_size());
?>

阅读全文 »

文件系统函数 readlink 返回符号连接指向的目标

发表日期:2021-07-01 08:55:44 | 来源: | 分类:文件系统函数

      示例1
<?php 
// output e.g. /boot/vmlinux-2.4.20-xfs
echo readlink('/vmlinuz');
?>

阅读全文 »

文件系统函数 fpassthru 输出文件指针处的所有剩余数据

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
// 以二进制格式打开文件
$name = './img/ok.png';
$fp = fopen($name, 'rb');
// 发送合适的报头
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));
// 发送图片并终止脚本
fpassthru($fp);
exit;
?>

阅读全文 »

文件系统函数 fputs fwrite() 的别名

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

fputs

(PHP 4, PHP 5, PHP 7, PHP 8)

fputsfwrite() 的别名

说明

此函数是该函数的别名:fwrite()

阅读全文 »

文件系统函数 fscanf 从文件中格式化输入

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
$handle = fopen("users.txt", "r");
while ($userinfo = fscanf($handle, "%s\t%s\t%s\n")) {
    list ($name, $profession, $countrycode) = $userinfo;
    //... do something with the values}
fclose($handle);
?>

      示例2
javier  argonaut        pe
hiroshi sculptor        jp
robert  slacker us
luigi   florist it

阅读全文 »

文件系统函数 fread 读取文件(可安全用于二进制文件)

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
// get contents of a file into a string$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
?>
      示例2
<?php 
$filename = "c:\\files\\somepic.gif";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);
?>
      示例3
<?php 
// 对 PHP 5 及更高版本
$handle = fopen("http://www.example.com/", "rb");
$contents = stream_get_contents($handle);
fclose($handle);
?>
      示例4
<?php 
$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
  $contents .= fread($handle, 8192);
}
fclose($handle);
?>

阅读全文 »

文件系统函数 fseek 在文件指针中定位

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
$fp = fopen('somefile.txt', 'r');
// read some data
$data = fgets($fp, 4096);
// move back to the beginning of the file
// same as rewind($fp);
fseek($fp, 0);
?>

阅读全文 »

文件系统函数 ftruncate 将文件截断到给定的长度

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
$filename = 'lorem_ipsum.txt';
$handle = fopen($filename, 'r+');
ftruncate($handle, rand(1, filesize($filename)));
rewind($handle);
echo fread($handle, filesize($filename));
fclose($handle);
?>

阅读全文 »

文件系统函数 fstat 通过已打开的文件指针取得文件信息

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
// 打开文件
$fp = fopen("/etc/passwd", "r");
// 取得统计信息
$fstat = fstat($fp);
// 关闭文件
fclose($fp);
// 只显示关联数组部分
print_r(array_slice($fstat, 13));
?>

阅读全文 »

文件系统函数 fgetcsv 从文件指针中读入一行并解析 CSV 字段

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0;
 $c < $num;
 $c++) {
            echo $data[$c] . "<br />\n";
        }
    }
    fclose($handle);
}
?>

阅读全文 »

文件系统函数 is_dir 判断给定文件名是否是一个目录

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
var_dump(is_dir('a_file.txt'));
var_dump(is_dir('bogus_dir/abc'));
var_dump(is_dir('..'));
 //one dir up?>

阅读全文 »

文件系统函数 ftell 返回文件指针读/写的位置

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
// opens a file and read some data$fp = fopen("/etc/passwd", "r");
$data = fgets($fp, 12);
// where are we ?echo ftell($fp);
 // 11fclose($fp);
?>

阅读全文 »

文件系统函数 fwrite 写入文件(可安全用于二进制文件)

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
function fwrite_stream($fp, $string) {
    for ($written = 0;
 $written < strlen($string);
 $written += $fwrite) {
        $fwrite = fwrite($fp, substr($string, $written));
        if ($fwrite === false) {
            return $written;
        }
    }
    return $written;
}
?>
      示例2
<?php 
$fp = fopen('data.txt', 'w');
fwrite($fp, '1');
fwrite($fp, '23');
fclose($fp);
// the content of 'data.txt' is now 123 and not 23!?>
      示例3
<?php 
$filename = 'test.txt';
$somecontent = "添加这些文字到文件\n";
// 首先我们要确定文件存在并且可写。
if (is_writable($filename)) {
    // 在这个例子里,我们将使用添加模式打开
    $filename,    
    // 因此,文件指针将会在文件的末尾,    
    // 那就是当我们使用fwrite()的时候,$somecontent将要写入的地方。    
    if (!$handle = fopen($filename, 'a')) {
         echo "不能打开文件 $filename";
         exit;
    }
    // 将$somecontent写入到我们打开的文件中。    
    if (fwrite($handle, $somecontent) === FALSE) {
        echo "不能写入到文件 $filename";
        exit;
    }
    echo "成功地将 $somecontent 写入到文件$filename";
    fclose($handle);
}
 else {
    echo "文件 $filename 不可写";
}
?>

阅读全文 »

文件系统函数 glob 寻找与模式匹配的文件路径

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
foreach (glob("*.txt") as $filename) {
    echo "$filename size " . filesize($filename) . "\n";
}
?>

阅读全文 »

文件系统函数 is_executable 判断给定文件名是否可执行

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
$file = '/home/vincent/somefile.sh';
if (is_executable($file)) {
    echo $file.' is executable';
}
 else {
    echo $file.' is not executable';
}
?>

阅读全文 »

文件系统函数 is_readable 判断给定文件名是否可读

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
$filename = 'test.txt';
if (is_readable($filename)) {
    echo 'The file is readable';
}
 else {
    echo 'The file is not readable';
}
?>

阅读全文 »

文件系统函数 is_file 判断给定文件名是否为一个正常的文件

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
var_dump(is_file('a_file.txt')) . "\n";
var_dump(is_file('/usr/bin/')) . "\n";
?>

阅读全文 »

文件系统函数 is_link 判断给定文件名是否为一个符号连接

发表日期:2021-07-01 08:55:43 | 来源: | 分类:文件系统函数

      示例1
<?php 
$link = 'uploads';
if (is_link($link)) {
    echo(readlink($link));
}
 else {
    symlink('uploads.php', $link);
}
?>

阅读全文 »

文件系统函数 file_get_contents 将整个文件读入一个字符串

发表日期:2021-07-01 08:55:42 | 来源: | 分类:文件系统函数

      示例1
<?php 
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
      示例2
<?php 
// 如果开启了严格类型,例如 declare(strict_types=1);
$file = file_get_contents('./people.txt', true);
// 否则就这样写$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);
?>
      示例3
<?php 
// 从第 21 个字符开始,读取 14 字符长度$section = file_get_contents('./people.txt', FALSE, NULL, 20, 14);
var_dump($section);
?>
      示例4
<?php 
// 创建 stream
$opts = array('http'=>array('method'=>"GET",'header'=>"Accept-language: en\r\n" ."Cookie: foo=bar\r\n"));
$context = stream_context_create($opts);
// 以下面设置的 HTTP 头来打开文件
$file = file_get_contents('http://www.example.com/', false, $context);
?>

阅读全文 »

文件系统函数 fileatime 取得文件的上次访问时间

发表日期:2021-07-01 08:55:42 | 来源: | 分类:文件系统函数

      示例1
<?php 
// 输出类似:somefile.txt was last accessed: December 29 2002 22:16:23.
$filename = 'somefile.txt';
if (file_exists($filename)) {
    echo "$filename was last accessed: " . date("F d Y H:i:s.", fileatime($filename));
}
?>

阅读全文 »

全部博文(1589)
集速网 copyRight © 2015-2025 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。