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

文件系统函数 fclose 关闭一个已打开的文件指针

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

      示例1
<?php 
$handle = fopen('somefile.txt', 'r');
fclose($handle);
?>

阅读全文 »

文件系统函数 diskfreespace disk_free_space() 的别名

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

diskfreespace

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

diskfreespacedisk_free_space() 的别名

说明

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

阅读全文 »

文件系统函数 feof 测试文件指针是否到了文件结束的位置

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

      示例1
<?php 
function safe_feof($fp, &$start = NULL) {
 $start = microtime(true);
 return feof($fp);
}
/* $fp 的赋值是由之前 fsockopen() 打开  */
$start = NULL;
$timeout = ini_get('default_socket_timeout');
while(!safe_feof($fp, $start) && (microtime(true) - $start) < $timeout){
 /* Handle */
}
?>

      示例2
<?php 
// 如果文件不可读取或者不存在,fopen 函数返回 FALSE$file = @fopen("no_such_file", "r");
// 来自 fopen 的 FALSE 会发出一条警告信息并在这里陷入无限循环while (!feof($file)) {
}
fclose($file);
?>

阅读全文 »

文件系统函数 fgetc 从文件指针中读取字符

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

      示例1
<?php 
$fp = fopen('somefile.txt', 'r');
if (!$fp) {
    echo 'Could not open file somefile.txt';
}
while (false !== ($char = fgetc($fp))) {
    echo "$char\n";
}
?>

阅读全文 »

文件系统函数 chmod 改变文件模式

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

      示例1
<?php 
chmod("/somedir/somefile", 755);
   // 十进制数,可能不对chmod("/somedir/somefile", "u+rwx,go+rx");
 // 字符串,不对chmod("/somedir/somefile", 0755);
  // 八进制数,正确的 mode 值?>

      示例2
<?php 
// Read and write for owner, nothing for everybody elsechmod("/somedir/somefile", 0600);
// Read and write for owner, read for everybody elsechmod("/somedir/somefile", 0644);
// Everything for owner, read and execute for otherschmod("/somedir/somefile", 0755);
// Everything for owner, read and execute for owner's groupchmod("/somedir/somefile", 0750);
?>

阅读全文 »

文件系统函数 fgets 从文件指针中读取一行

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

      示例1
<?php 
$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        echo $buffer;
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}
?>

阅读全文 »

文件系统函数 fgetss 从文件指针中读取一行并过滤掉 HTML 标记

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

      示例1
<?php 
$str = <<<EOD<html><body> <p>Welcome! Today is the <?php echo(date('jS'));
 ?> of <?= date('F');
 ?>.</p></body></html>Text outside of the HTML block.EOD;
file_put_contents('sample.php', $str);
$handle = @fopen("sample.php", "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgetss($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>

阅读全文 »

文件系统函数 file_exists 检查文件或目录是否存在

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

      示例1
<?php 
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
    echo "The file $filename exists";
}
 else {
    echo "The file $filename does not exist";
}
?>

阅读全文 »

文件系统函数 file_put_contents 将一个字符串写入文件

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

      示例1
<?php 
$file = 'people.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= "John Smith\n";
// Write the contents back to the file
file_put_contents($file, $current);
?>
      示例2
<?php 
$file = 'people.txt';
// The new person to add to the file
$person = "John Smith\n";
// Write the contents to the file, 
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same time
file_put_contents($file, $person, FILE_APPEND | LOCK_EX);
?>

阅读全文 »

文件系统函数 chgrp 改变文件所属的组

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

      示例1
<?php 
$filename = 'shared_file.txt';
$format = "%s's Group ID @ %s: %d\n";
printf($format, $filename, date('r'), filegroup($filename));
chgrp($filename, 8);
clearstatcache();
 // do not cache filegroup() resultsprintf($format, $filename, date('r'), filegroup($filename));
?>

阅读全文 »

文件系统函数 copy 拷贝文件

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

      示例1
<?php 
$file = 'example.txt';
$newfile = 'example.txt.bak';
if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}
?>

阅读全文 »

文件系统函数 clearstatcache 清除文件状态缓存

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

      示例1
<?php 
$file = 'output_log.txt';
function get_owner($file){
    $stat = stat($file);
    $user = posix_getpwuid($stat['uid']);
    return $user['name'];
}
$format = "UID @ %s: %s\n";
printf($format, date('r'), get_owner($file));
chown($file, 'ross');
printf($format, date('r'), get_owner($file));
clearstatcache();
printf($format, date('r'), get_owner($file));
?>

阅读全文 »

Fileinfo 函数 finfo_filefinfo::file 返回一个文件的信息

发表日期:2021-07-01 08:55:36 | 来源: | 分类:Fileinfo 函数

      示例1
<?php 
$finfo = finfo_open(FILEINFO_MIME_TYPE);
 // 返回 mime 类型
 foreach (glob("*") as $filename) {
    echo finfo_file($finfo, $filename) . "\n";
}
finfo_close($finfo);
?>

阅读全文 »

Fileinfo 函数 finfo_close 关闭 fileinfo 资源

发表日期:2021-07-01 08:55:36 | 来源: | 分类:Fileinfo 函数

finfo_close

(PHP >= 5.3.0, PHP 7, PHP 8, PECL fileinfo >= 0.1.0)

finfo_close关闭 fileinfo 资源

说明

finfo_close(resource $finfo): bool

关闭 finfo_open() 函数所返回的 fileinfo 资源。

参数

finfo

finfo_open() 函数所返回的 fileinfo 资源。

返回值

成功时返回 true, 或者在失败时返回 false

阅读全文 »

Fileinfo 函数 finfo_bufferfinfo::buffer 返回一个字符串缓冲区的信息

发表日期:2021-07-01 08:55:35 | 来源: | 分类:Fileinfo 函数

      示例1
<?php 
$finfo = new finfo(FILEINFO_MIME);
echo $finfo->buffer($_POST["script"]) . "\n";
?>

阅读全文 »

Fileinfo 函数 finfo_set_flagsfinfo::set_flags 设置 libmagic 配置选项

发表日期:2021-07-01 08:55:35 | 来源: | 分类:Fileinfo 函数

finfo_set_flags

finfo::set_flags

(PHP >= 5.3.0, PHP 7, PHP 8, PECL fileinfo >= 0.1.0)

finfo_set_flags -- finfo::set_flags设置 libmagic 配置选项

说明

过程化风格

finfo_set_flags(resource $finfo, int $options): bool

面向对象风格

public finfo::set_flags(int $options): bool

此函数用来设置 Fileinfo 选项。 这些选项也可以在调用 finfo_open() 或者其他 Fileinfo 函数时直接指定。

参数

finfo

finfo_open() 返回的资源。

options

一个 Fileinfo 常量 或多个 Fileinfo 常量 进行逻辑或运算。

返回值

成功时返回 true, 或者在失败时返回 false

阅读全文 »

Fileinfo 函数 finfo_openfinfo::__construct 创建一个 fileinfo 资源

发表日期:2021-07-01 08:55:35 | 来源: | 分类:Fileinfo 函数

      示例1
<?php 
$finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic");
 // 返回 mime 类型/* get mime-type for a specific file */
$filename = "/usr/local/something.txt";
echo $finfo->file($filename);
?>
      示例2
<?php 
$finfo = finfo_open(FILEINFO_MIME, "/usr/share/misc/magic");
 // 返回 mime 类型
 if (!$finfo) {
    echo "Opening fileinfo database failed";
    exit();
}
/* 获取指定文件的 mime 类型 */
$filename = "/usr/local/something.txt";
echo finfo_file($finfo, $filename);
/* 关闭资源 */
finfo_close($finfo);
?>

阅读全文 »

Fileinfo 函数 mime_content_type 检测文件的 MIME 类型

发表日期:2021-07-01 08:55:35 | 来源: | 分类:Fileinfo 函数

      示例1
<?php 
echo mime_content_type('php.gif') . "\n";
echo mime_content_type('test.php');
?>

阅读全文 »

目录函数 closedir 关闭目录句柄

发表日期:2021-07-01 08:55:31 | 来源: | 分类:目录函数

      示例1
<?php 
$dir = "/etc/php5/";
// Open a known directory, read directory into variable and then close
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        $directory = readdir($dh);
        closedir($dh);
    }
}
?>

阅读全文 »

目录函数 dir 返回一个 Directory 类实例

发表日期:2021-07-01 08:55:31 | 来源: | 分类:目录函数

      示例1
<?php 
$d = dir("/etc/php5");
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
   echo $entry."\n";
}
$d->close();
?>

阅读全文 »

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