PHP文件相关函数试题
2016-08-08 20:58
309 查看
一.问答题
1.返回路径中的文件名部分的函数是什么?
2.改变文件模式的函数是什么?
3.拷贝文件的函数是什么?
4.返回路径中的目录部分的函数是什么?
5.将上传的文件移动到指定位置的函数是?
6.返回规范化的绝对路径名的函数是什么?
二.编程题
1.请用三种方法写出函数,获取某个目录下所有文件和文件夹名的关联数组,要求给函数传一个路径参数,返回一个数组,格式为:array('dir'=>array('dir1','dir2'...),'file'=>array())
2.封装一个系统文件类,类中方法包括:判断文件是否存在,获取文件内容(包括锁和不锁文件),输入内容到一个文件,追加内容到文件,删除文件,移动文件,拷贝文件,文件的文件名部分,文件的目录部分,文件的后缀名部分,文件的mine类型,文件的大小,获取文件上一次修改时间,判断是否为路径,判断文件是否可写,判断是否为文件,创建文件夹,复制一个目录,删除一个目录。
答案
一.问答题
1.string basename ( string
2.bool chmod ( string
3.bool copy ( string
4.string dirname ( string
5.bool move_uploaded_file ( string
6.string realpath ( string
二.编程题
1
2.
1.返回路径中的文件名部分的函数是什么?
2.改变文件模式的函数是什么?
3.拷贝文件的函数是什么?
4.返回路径中的目录部分的函数是什么?
5.将上传的文件移动到指定位置的函数是?
6.返回规范化的绝对路径名的函数是什么?
二.编程题
1.请用三种方法写出函数,获取某个目录下所有文件和文件夹名的关联数组,要求给函数传一个路径参数,返回一个数组,格式为:array('dir'=>array('dir1','dir2'...),'file'=>array())
2.封装一个系统文件类,类中方法包括:判断文件是否存在,获取文件内容(包括锁和不锁文件),输入内容到一个文件,追加内容到文件,删除文件,移动文件,拷贝文件,文件的文件名部分,文件的目录部分,文件的后缀名部分,文件的mine类型,文件的大小,获取文件上一次修改时间,判断是否为路径,判断文件是否可写,判断是否为文件,创建文件夹,复制一个目录,删除一个目录。
答案
一.问答题
1.string basename ( string
$path[, string
$suffix] )
2.bool chmod ( string
$filename, int
$mode)
3.bool copy ( string
$source, string
$dest[, resource
$context] )
4.string dirname ( string
$path)
5.bool move_uploaded_file ( string
$filename, string
$destination)
6.string realpath ( string
$path)
二.编程题
1
function scanDir1($dir = './'){ $result['dir'] = $result['file'] = array(); if(!is_dir($dir)) return $result; foreach (scandir($dir) as $df) { if($df==='.'||$df==='..') continue; if(is_dir($dir.'/'.$df)) $result['dir'][] = $df; if(is_file($dir.'/'.$df)) $result['file'][] = $df; } return $result; } function scanDir2($dir = './'){ $result['dir'] = $result['file'] = array(); if(!is_dir($dir)) return $result; $handle = dir($dir); while (($df = $handle -> read()) !== false) { if($df==='.'||$df==='..') continue; if(is_dir($dir.'/'.$df)) $result['dir'][] = $df; if(is_file($dir.'/'.$df)) $result['file'][] = $df; } $handle -> close(); return $result; } function scanDir3($dir = './'){ $result['dir'] = $result['file'] = array(); if(!is_dir($dir)) return $result; $handle = opendir($dir); while (($df = readdir($handle)) !== false) { if($df==='.'||$df==='..') continue; if(is_dir($dir.'/'.$df)) $result['dir'][] = $df; if(is_file($dir.'/'.$df)) $result['file'][] = $df; } return $result; }
2.
<?php class FileSystem{ public function exists($path) { return file_exists($path); } public function isFile($path) { return is_file($path); } public function isDir($path) { return is_dir($path); } public function get($path,$lock = false) { if(!$this->exists($path)) return ''; if($lock){ return $this -> lockGet($path); }else{ return file_get_contents($path); } } private function lockGet($path) { $contents = ''; $handle = fopen($path, 'r'); if($handle){ try { if(flock($handle, LOCK_SH)){ while (!feof($handle)) { $contents .= fread($handle, 1048576); } } } finally { fclose($handle); } } return $contents; } public function put($path,$contents,$lock = false) { return file_put_contents($path,$contents,$lock?LOCK_SH:0); } public function append($path,$contents) { return file_put_contents($path,$contents,FILE_APPEND); } public function delete($path) { if($this->isFile($path)){ return unlink($path); }else if($this->isDir($path)){ foreach (scandir($path) as $df) { if($df!=='.'||$df!=='..'){ $this->delete($path.'/'.$df); } } rmdir($path); } } public function move($path,$target) { return rename($path,$target); } public function copy($path,$target) { return copy($path,$target); } public function name($path) { return pathinfo($path,PATHINFO_FILENAME); } public function dirname($path) { return pathinfo($path,PATHINFO_DIRNAME); } public function extension($path) { return pathinfo($path,PATHINFO_EXTENSION); } public function type($path) { return filetype($path); } public function size($path) { return filesize($path); } public function lastModified($path) { return filemtime($path); } public function isWritable($path) { return is_writable($path); } public function makeDir($path,$mode = 0755) { return @mkdir($path,$mode); } }
相关文章推荐
- PHP中文件类型 文件属性 路径以及 文件相关的函数
- 利用php内置的svn函数实现的根据svn版本号导出相关文件的功能
- 利用php内置的svn函数实现的根据svn版本号导出相关文件的功能
- PHP相关文件操作函数和jquery.Form文件上传
- PHP中对已打开文件资源进行操作的相关函数
- PHP处理文件和操作系统的相关函数
- PHP文件读写操作相关函数学习资料笔记
- PHP编码相关函数试题
- PHP - Manual手册 - Function Reference函数参考 - File System Related Extensions文件系统相关扩展 - Filesystem文件系统 - Filesystem Functions文件系统函数 -
- 关于PHP-Zend framework2 框架 学习过程。 阅前须知: ZF2中的配置文件是可以静态文件配置来注册和通过相关函数动态注册。 1.EventManager(事件驱动),关于事件驱动,在ZF2相关资料没有详细说明,可以参考ANDROID的事件驱动,MFC的消息响应/事件驱动。
- PHP文件读写操作相关函数总结
- PHP访问文件或者文件夹或者文件夹相关函数。
- PHP获取文件创建时间和修改时间相关函数
- PHP访问文件或者文件夹或者文件夹相关函数。
- PHP - Manual手册 - Function Reference函数参考 - File System Related Extensions文件系统相关扩展 - Filesystem文件系统 - Filesystem Functions文件系统函数 -
- php文件相关函数介绍
- PHP操作文件和目录的相关函数
- PHP - Manual手册 - Function Reference函数参考 - File System Related Extensions文件系统相关扩展 - Directories目录 - Directory Functions目录函数 - sca
- PHP之curl函数相关试题
- PHP文件属性相关函数