一.问答题

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. 常用Oracle分析函数详解 [http://www.cnblogs.com/benio/archive/2011/06/01/2066106.html]

      学习步骤:1. 拥有Oracle EBS demo 环境 或者 PROD 环境2. copy以下代码进 PL/SQL3. 配合解释分析结果4. 如果网页有点乱请复制到TXT中查看 /*假设一个经理 ...

  2. Linux操作系统信息查看命令

    1. 查看系统内核信息 uname -a 2. 操作系统版本  cat /etc/issue | grep Linux 3. 查看CPU型号 cat /proc/cpuinfo | grep name ...

  3. <hr/>标签改变颜色注意事项

    1.css改变颜色 <hr style="border:0;background-color:#093;height:1px;">   注意: 如果不加border:0 ...

  4. tcpdump的源码分析

    在源文件 tcpdump.c 中: 结构体数组“static struct printer printers[]”定义了tcpdump所跟参数及其对一个的处理函数. struct printer {  ...

  5. php基础的第一天 任务点滴,event对象方法概括 ing....

    day1 任务 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...

  6. Openjudge-计算概论(A)-整数的个数

    描述: 给定k(1<k<100)个正整数,其中每个数都是大于等于1,小于等于10的数.写程序计算给定的k个正整数中,1,5和10出现的次数.输入输入有两行:第一行包含一个正整数k,第二行包 ...

  7. Python in minute

    Python 性能优化相关专题:    https://www.ibm.com/developerworks/cn/linux/l-cn-python-optim/   Python wikipedi ...

  8. android中对Bitmap图片设置任意角为圆角

    http://blog.csdn.net/l448288137/article/details/48276681 最近项目开发中使用到了圆角图片,网上找到的圆角图片控件大多比较死板,只可以全圆角.其中 ...

  9. CodeFroces--Good Bye 2016-A-New Year and Hurry(水题-模拟)

    A. New Year and Hurry time limit per test 1 second memory limit per test 256 megabytes input standar ...

  10. memcached + php 扩展 for ubuntu

    1.安装memcached apt-get install memcached 2.安装php memcached 扩展 apt-get install php5-memcache 3.启动memca ...