PHP常用函数总结(180多个)

2019-05-02 07:19:53于丽

144.opendir(): 打开目录句柄

$fp=opendir('E:/xampp/htdocs/php/study/19');
echo readdir($fp);
closedir($fp);

调用: resource opendir ( string $path [, resource $context ] ) 返回值: 如果成功则返回目录句柄的 resource,失败则返回FALSE

145.readdir(): 从目录句柄中读取条目

$fp=opendir('E:/xampp/htdocs/php/study/19');
echo readdir($fp);
closedir($fp);

调用: string readdir ( resource $dir_handle ) 返回值: 返回目录中下一个文件的文件名。文件名以在文件系统中的排序返回

146.closedir(): 关闭目录句柄

$fp=opendir('E:/xampp/htdocs/php/study/19');
echo readdir($fp);
closedir($fp);

调用: void closedir ( resource $dir_handle ) 关闭由 dir_handle 指定的目录流。流必须之前被opendir() 所打开 147.rewinddir() : 倒回目录句柄

 

 $fp=opendir('E:/xampp/htdocs/php/study/19');
 echo readdir($fp).'<br />';
 echo readdir($fp).'<br />';
 echo readdir($fp).'<br />';
 rewinddir($fp);
 echo readdir($fp).'<br />';
 closedir($fp);

调用: void rewinddir ( resource $dir_handle ) 输出: 将 dir_handle 指定的目录流重置到目录的开头 148.mkdir(): 新建目录

    mkdir('123');
调用: bool mkdir ( string $pathname [, int $mode [, bool $recursive [, resource $context ]]] ) 输出: 尝试新建一个由 pathname 指定的目录

149.rmdir(): 删除目录

    rmdir('123');
调用: bool rmdir ( string $dirname ) 输出: 尝试删除 dirname 所指定的目录。目录必须是空的,而且要有相应的权限。如果成功则返回TRUE,失败则返回 FALSE

150.unlink(): 删除文件

 unlink('123/1.txt');
 rmdir('123');

调用: bool unlink ( string $filename ) 输出: 删除 filename 。和 Unix C 的 unlink() 函数相似。如果成功则返回 TRUE,失败则返回 FALSE

151.copy(): 拷贝文件

    copy('index.php','index.php.bak');
调用: bool copy ( string $source , string $dest ) 输出: 将文件从 source 拷贝到 dest. 如果成功则返回TRUE,失败则返回 FALSE

152.rename(): 重命名一个文件或目录

    rename('tx.txt','txt.txt');
调用: bool rename ( string $oldname , string $newname [, resource $context ] ) 输出: 如果成功则返回 TRUE,失败则返回 FALSE

文件的上传与下载

153.is_uploaded_file():判断文件是否是通过 HTTP POST上传的

 if(is_uploaded_file($_FILES['bus']['tmp_name'])){
 if( move_uploaded_file($_FILES['bus']['tmp_name'],
 $NewPath) ){
 echo '上传成功<br /><img src="'.$NewPath.'">';
 }else{
 exit('失败');
 }
 }else{
 exit('不是上传文件');
 }

调用: bool is_uploaded_file ( string $filename )  

154.move_uploaded_file(): 将上传的文件移动到新位置

相关文章 大家在看