一.问答题

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文件相关函数试题的更多相关文章

  1. Django+七牛上传+查看+下载文件相关函数,新整理未完全测试

    M class File(models.Model): # 文档模型 name = models.CharField(max_length=255) staff = models.ForeignKey ...

  2. PHP回顾(4)文件相关函数

    touch()          创建文件 (修改时间,不存在时创建) copy()            复制文件,复制过程中可以修改文件名 rename()        重命名 或  移动文件  ...

  3. PHP编码相关函数试题

    1.检查字符串在指定的编码里是否有效的函数是什么? 2.获取字符编码的函数是什么? 3.解析 GET/POST/COOKIE 数据并设置全局变量的函数是什么? 4.大小写不敏感地查找字符串在另一个字符 ...

  4. day08-Python运维开发基础(文件操作与相关函数、函数基础)

    1. 文件操作及相关函数 # ### 文件操作 """ fp = open("文件名称",mode=模式,encoding=编码集) fp 文件io对 ...

  5. VC++ CArchive及简单的文件操作方法

    CArchive 方法用于存取文件 我向你推荐的是使用CArchive,它的使用方法简单且功能十分强大.首先还是用CFile声明一个对象,然后用这个对象的指针做参数声明一个CArchive对象,你就可 ...

  6. 【Linux C中文函数手册】文件内容控制函数

    文件内容控制函数 1)clearerr 清除文件流的错误旗标 相关函数 feof表头文件 #include<stdio.h>定义函数 void clearerr(FILE * stream ...

  7. VC的文件操作

    各种关于文件的操作在程序设计中是十分常见,如果能对其各种操作都了如指掌,就可以根据实际情况找到最佳的解决方案,从而在较短的时间内编写出高效的代码,因而熟练的掌握文件操作是十分重要的.本文将对Visua ...

  8. ubuntu Linux下C语言open函数打开或创建文件与read,write函数详细讲解

    open(打开文件) 相关函数 read,write,fcntl,close,link,stat,umask,unlink,fopen 表头文件 #include<sys/types.h> ...

  9. CFile、CStdioFile、FILE和其他文件操作(转+总结)

    CFile.CStdioFile.FILE和其他文件操作(转+总结) 2010-04-10 20:36:33|  分类: VC++|举报|字号 订阅     下载LOFTER我的照片书  |     ...

随机推荐

  1. ios 实现在tableViewCell上面添加长按手势 删除该条cell以及列表后台数据等

    自己的代码  需要   把属性更改成自己要使用的 //创建长按手势 在cellForRowAtIndexPath代理方法中 UILongPressGestureRecognizer *longPres ...

  2. POJ 3264 RMQ裸题

    POJ 3264 题意:n个数,问a[i]与a[j]间最大值与最小值之差. 总结:看了博客,记下了模板,但有些地方还是不太理解. #include<iostream> #include&l ...

  3. String类之substring--->查找某位置对应的字

    以下方法都是java内置类String类的内置方法(不是构造方法哦,就是普通的方法),不需要我们写,直接拿过来用即可. substring方法对应Api介绍   查找字符串中的 从int beginI ...

  4. [妙味JS基础]第七课:运算符、流程控制

    知识点总结 &&(与).||(或).!(非) 与: alert(20 && 20>100) => false alert(20 && 20& ...

  5. Llinux环境下编译并使用OpenCV

    http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html http://stacko ...

  6. AnimatorController动画融合树

    通过Unity动画状态机,能帮我们轻松处理转换各个动画片断,达到想要的效果,但是如果仅仅是一个个动画的硬生生的切换,那么看起来就非常突然,而不真实了,在质量要求比较高的游戏中,特别是动作游戏,我们就不 ...

  7. Traffic Ccontrol(流量控制)

    linux有一个成熟的带宽供给系统,称为Traffic Control(流量控制).这个系统支持各种方式进行分类.排序.共享和限制出入流量. 一.基础知识 让ip显示我们的链路 ip link  li ...

  8. HDU 1361 Parencodings(栈)

    题目链接 Problem Description Let S = s1 s2 … s2n be a well-formed string of parentheses. S can be encode ...

  9. 使用rdesktop远程连接Windows桌面

    之前使用的是KDE下的krdc.该程序的Grab Keys功能存在bug,导致Alt+TAB大多数时候不能被捕捉,从而无法使用键盘切换窗口.不过,其全屏功能是正常的,在多显示器的情况下,全屏只在一个屏 ...

  10. js添加div

    有这样一段div布局 <div class="clearfix">    <p class="left c">        <s ...