Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > PHP > PHP中文件目录函数
【标  题】:PHP中文件目录函数
【关键字】:PHP
【来  源】:http://www.cublog.cn/u/19869/showart.php?id=127662

PHP中文件目录函数

Your Ad Here

readdir

readdir -- 从目录句柄中读取条目

说明

string readdir ( resource dir_handle )

返回目录中下一个文件的文件名。文件名以在文件系统中的排序返回。

参数

dir_handle

目录句柄的 resource,之前由 opendir() 打开

返回值

成功则返回文件名,失败返回 FALSE

范例

例子 1. 列出目录中的所有文件

请留意下面例子中检查 readdir() 返回值的风格。这里明确地测试返回值是否全等于(值和类型都相同――更多信息参见比较运算符FALSE,否则任何目录项的名称求值为 FALSE 的都会导致循环停止(例如一个目录名为“0”)。

<?php
// 注意在 4.0.0-RC2 之前不存在 !== 运算符

if ($handle = opendir('/path/to/files'
)) {
   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
);
}
?>

例子 2. 列出当前目录的所有文件并去掉 ...

<?php
if ($handle = opendir('.'
)) {
   while (
false !== ($file = readdir($handle
))) {
       if (
$file != "." && $file != ".."
) {
           echo
"$file\n"
;
       }
   }
  
closedir($handle
);
}
?>

chmod

chmod -- 改变文件模式

说明

bool chmod ( string filename, int mode )

尝试将 filename 所指定文件的模式改成 mode 所给定的。

注意 mode 不会被自动当成八进制数值,而且也不能用字符串(例如 "g+w")。要确保正确操作,需要给 mode 前面加上 0:

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

mode 参数包含三个八进制数按顺序分别指定了所有者、所有者所在的组以及所有人的访问限制。每一部分都可以通过加入所需的权限来计算出所要的权限。数字 1 表示使文件可执行,数字 2 表示使文件可写,数字 4 表示使文件可读。加入这些数字来制定所需要的权限。有关 UNIX 系统的文件权限可以阅读手册“man 1 chmod”和“man 2 chmod”。

<?php
// Read and write for owner, nothing for everybody else
chmod("/somedir/somefile", 0600
);

// Read and write for owner, read for everybody else
chmod("/somedir/somefile", 0644
);

// Everything for owner, read and execute for others
chmod("/somedir/somefile", 0755
);

// Everything for owner, read and execute for owner's group
chmod("/somedir/somefile", 0750
);
?>

如果成功则返回 TRUE,失败则返回 FALSE

注: 当前用户指的是执行 PHP 的用户。很可能和通常的 shell 或者 FTP 用户不是同一个。在大多数系统下文件模式只能被文件所有者的用户改变。

注: 本函数不能作用于远程文件,被检查的文件必须通过服务器的文件系统访问。

注: 安全模式打开的时候,PHP 会检查所操作的文件是否和正在执行的脚本具有相同的 UID (所有者)。要注意的是,不能修改 SUID,SGID 和 sticky bits。

 

exec

exec -- Execute an external program

说明

string exec ( string command [, array &output [, int &return_var]] )

exec() executes the given command.

参数

command

The command that will be executed.

output

If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec().

return_var

If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable.

返回值

The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

To get the output of the executed command, be sure to set and use the output parameter.

范例

例子 1. An exec() example

<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami'
);
?>

Perl程序设计中的函数(子程序):【上一篇】
php上传文件时应注意的几个细节:【下一篇】
【相关文章】
  • soap使用方法(php5.12下测试通过)
  • ASP PHP JSP 之比较
  • 没有发现 PHP 的扩展设置mbstring, 而当前系统好像在使用宽字符集。没有 mbstring
  • php显示空白解决(freebsd)
  • apache2.2+mysql5.0+php5.1+Discuz!4.1配置完全手册
  • PHP读取Excel文件
  • windows IIS上配置PHP支持
  • 利用 QQWry.Dat 实现 IP 地址高效检索(PHP)
  • 如何从一个php文件向另一个地址post数据,不用表单和隐藏的变量
  • RedHatAS4下Apache2+MySQL+Php+Tomcat整合及虚拟主机配置
  • 【随机文章】
  • Java初学者都必须理解的问题
  • KV3000密钥盘源程序 下
  • asp+的论坛列表程序---代码部分
  • 察看别人在登陆后输入的命令
  • 深入浅出Shell 编程:Unix/Linux 命令
  • MySQL手册
  • 还有亨丽哀大太本人,过去都不曾狠这位花花公子会过面,但凭黄昏时平台上一次两小时的交谈,再加上一小时在...
  • 大家给推荐一下从datagrid到出数据到excel的好方法或者是例子。谢谢
  • Red Hat Enterprise Linux4
  • 桌面背景任你改
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.