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

文件系统函数 tempnam 建立一个具有唯一文件名的文件

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

      示例1
<?php 
$tmpfname = tempnam("/tmp", "FOO");
$handle = fopen($tmpfname, "w");
fwrite($handle, "writing to tempfile");
fclose($handle);
// do here something
unlink($tmpfname);
?>

阅读全文 »

文件系统函数 symlink 建立符号连接

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

      示例1
<?php 
$target = 'uploads.php';
$link = 'uploads';
symlink($target, $link);
echo readlink($link);
?>

阅读全文 »

文件系统函数 umask 改变当前的 umask

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

      示例1
<?php 
$old = umask(0);
chmod("/path/some_dir/some_file.txt", 0755);
umask($old);
// Checking
if ($old != umask()) {
    die('An error occured while changing back the umask');
}
?>

阅读全文 »

iconv 函数 iconv_get_encoding 获取 iconv 扩展的内部配置变量

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

      示例1
<?php 
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "ISO-8859-1");
var_dump(iconv_get_encoding('all'));
</pre>

阅读全文 »

iconv 函数 iconv_mime_decode_headers 一次性解码多个 MIME 头字段

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

      示例1
<?php 
$headers_string = <<<EOFSubject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?=To: example@example.comDate: Thu, 1 Jan 1970 00:00:00 +0000Message-Id: <example@example.com>Received: from localhost (localhost [127.0.0.1]) by localhost    with SMTP id example for <example@example.com>;
    Thu, 1 Jan 1970 00:00:00 +0000 (UTC)    (envelope-from example-return-0000-example=example.com@example.com)Received: (qmail 0 invoked by uid 65534);
 1 Thu 2003 00:00:00 +0000EOF;
$headers =  iconv_mime_decode_headers($headers_string, 0, "ISO-8859-1");
print_r($headers);
?>

阅读全文 »

文件系统函数 lchgrp 修改符号链接的所有组

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

      示例1
<?php 
$target = 'output.php';
$link = 'output.html';
symlink($target, $link);
lchgrp($link, 8);
?>

阅读全文 »

文件系统函数 is_uploaded_file 判断文件是否是通过 HTTP POST 上传的

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

      示例1
<?php 
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
   echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n";
   echo "Displaying contents\n";
   readfile($_FILES['userfile']['tmp_name']);
}
 else {
   echo "Possible file upload attack: ";
   echo "filename '". $_FILES['userfile']['tmp_name'] . "'.";
}
?>

阅读全文 »

文件系统函数 is_writable 判断给定的文件名是否可写

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

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

阅读全文 »

文件系统函数 is_writeable is_writable() 的别名

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

is_writeable

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

is_writeableis_writable() 的别名

说明

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

阅读全文 »

文件系统函数 lstat 给出一个文件或符号连接的信息

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

      示例1
<?php 
symlink('uploads.php', 'uploads');
// Contrast information for uploads.php and uploads
array_diff(stat('uploads'), lstat('uploads'));
?>

阅读全文 »

文件系统函数 link 建立一个硬连接

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

      示例1
<?php 
$target = 'source.ext';
 // This is the file that already exists$link = 'newfile.ext';
 // This the filename that you want to link it tolink($target, $link);
?>

阅读全文 »

文件系统函数 lchown 修改符号链接的所有者

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

      示例1
<?php 
$target = 'output.php';
$link = 'output.html';
symlink($target, $link);
lchown($link, 8);
?>

阅读全文 »

文件系统函数 mkdir 新建目录

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

      示例1
<?php 
mkdir("/path/to/my/dir", 0700);
?>
      示例2
<?php 
// Desired folder structure
$structure = './depth1/depth2/depth3/';
// To create the nested structure, the $recursive parameter 
// to mkdir() must be specified.
if (!mkdir($structure, 0777, true)) {
    die('Failed to create folders...');
}
// ...?>

阅读全文 »

文件系统函数 move_uploaded_file 将上传的文件移动到新位置

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

      示例1
<?php 
$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        $name = $_FILES["pictures"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
    }
}
?>

阅读全文 »

文件系统函数 parse_ini_string 解析配置字符串

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

parse_ini_string

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

parse_ini_string解析配置字符串

说明

parse_ini_string(string $ini, bool $process_sections = false, int $scanner_mode = INI_SCANNER_NORMAL): array

parse_ini_string() 返回 ini 字符串解析后的关联数组

ini 字符串的格式参考 php.ini

参数

ini

ini 字符串内容

process_sections

设置 process_sections 参数为 true,得到一个多维数组,包含名称和设置。process_sections 默认为 false

scanner_mode

可以是 INI_SCANNER_NORMAL (默认)或 INI_SCANNER_RAW 。如果是 INI_SCANNER_RAW,那么选项值不会被解析。

As of PHP 5.6.1 can also be specified as INI_SCANNER_TYPED. In this mode boolean, null and integer types are preserved when possible. String values "true", "on" and "yes" are converted to true. "false", "off", "no" and "none" are considered false. "null" is converted to null in typed mode. Also, all numeric strings are converted to integer type if it is possible.

返回值

执行成功返回一个关联数组,返回 false 为失败

注释

注意: 保留关键字不能作为 ini 的键,包括 null, yes, no, true, false, on, off, none以及空值,off,no 和错误的结果集,值为 yes 和 正确的结果集。除非使用 INI_SCANNER_TYPED 模式。 字符 ?{}|&~![()^" 不能在任何地方使用作为键和有特殊意义的值。

参见

阅读全文 »

文件系统函数 parse_ini_file 解析一个配置文件

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

      示例1
<?php 
define('BIRD', 'Dodo bird');
// Parse without sections
$ini_array = parse_ini_file("sample.ini");
print_r($ini_array);
// Parse with sections
$ini_array = parse_ini_file("sample.ini", true);
print_r($ini_array);
?>
      示例2
<?php 
// A simple function used for comparing the results below
function yesno($expression){
    return($expression ? 'Yes' : 'No');
}
// Get the path to php.ini using the php_ini_loaded_file() 
// function available as of PHP 5.2.4
$ini_path = php_ini_loaded_file();
// Parse php.ini
$ini = parse_ini_file($ini_path);
// Print and compare the values, note that using get_cfg_var()
// will give the same results for parsed and loaded here
echo '(parsed) magic_quotes_gpc = ' . yesno($ini['magic_quotes_gpc']) . PHP_EOL;
echo '(loaded) magic_quotes_gpc = ' . yesno(get_cfg_var('magic_quotes_gpc')) . PHP_EOL;
?>

阅读全文 »

文件系统函数 pclose 关闭进程文件指针

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

      示例1
<?php 
$handle = popen('/bin/ls', 'r');
pclose($handle);
?>

阅读全文 »

文件系统函数 pathinfo 返回文件路径的信息

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

      示例1
<?php 
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n";
 // since PHP 5.2.0?>

      示例2
<?php 
$path_parts = pathinfo('/path/emptyextension.');
var_dump($path_parts['extension']);
$path_parts = pathinfo('/path/noextension');
var_dump($path_parts['extension']);
?>

阅读全文 »

文件系统函数 readfile 输出文件

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

      示例1
<?php 
$file = 'monkey.gif';
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment;
 filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}
?>

阅读全文 »

文件系统函数 realpath_cache_get 获取真实目录缓存的详情

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

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

阅读全文 »

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