首页 > php教程 > php手册 > PHP常用的基本文件和目录操作总结,

PHP常用的基本文件和目录操作总结,

WBOY
发布: 2016-06-13 09:24:46
原创
1047 人浏览过

PHP常用的基本文件和目录操作总结,

来源:http://www.ido321.com/835.html

一、基本文件的操作

文件的基本操作有:文件判断、目录判断、文件大小、读写性判断、存在性判断及文件时间等

<span id="lnum1">   1:</span><span> <?php</span>
登录后复制
<span id="lnum2">   2:</span><span>     header(<span>"content-type"</span>,<span>"text/html;charset=utf-8"</span>);</span>
登录后复制
<span id="lnum3">   3:</span><span> <span>/*</span></span>
登录后复制
<span id="lnum4">   4:</span><span> <span>*声明一个函数,传入文件名获取文件属性</span></span>
登录后复制
<span id="lnum5">   5:</span><span> <span>*@param string $fileName 文件名称</span></span>
登录后复制
<span id="lnum6">   6:</span><span> <span>*/</span></span>
登录后复制
<span id="lnum7">   7:</span><span> <span>function</span> getFilePro($fileName)</span>
登录后复制
<span id="lnum8">   8:</span><span> {</span>
登录后复制
登录后复制
<span id="lnum9">   9:</span><span>     <span>if</span>(!file_exists($fileName))</span>
登录后复制
<span id="lnum10">  10:</span><span>     {</span>
登录后复制
<span id="lnum11">  11:</span><span>         <span>echo</span> <span>'文件不存在<br/>'</span>;</span>
登录后复制
<span id="lnum12">  12:</span><span>         <span>return</span>;</span>
登录后复制
<span id="lnum13">  13:</span><span>     }</span>
登录后复制
<span id="lnum14">  14:</span><span>     <span>/*是否是普通文件*/</span></span>
登录后复制
<span id="lnum15">  15:</span><span>     <span>if</span>(is_file($fileName))</span>
登录后复制
<span id="lnum16">  16:</span><span>     {</span>
登录后复制
登录后复制
<span id="lnum17">  17:</span><span>         <span>echo</span> $fileName.<span>'是一个文件<br/>'</span>;</span>
登录后复制
<span id="lnum18">  18:</span><span>     }</span>
登录后复制
<span id="lnum19">  19:</span><span>     <span>/*是否是目录*/</span></span>
登录后复制
<span id="lnum20">  20:</span><span>     <span>if</span>(is_dir($fileName))</span>
登录后复制
<span id="lnum21">  21:</span><span>     {</span>
登录后复制
<span id="lnum22">  22:</span><span>         <span>echo</span> $fileName.<span>'是一个目录'</span>;</span>
登录后复制
<span id="lnum23">  23:</span><span>     }</span>
登录后复制
<span id="lnum24">  24:</span><span>     <span>/*输出文件的型态*/</span></span>
登录后复制
<span id="lnum25">  25:</span><span>     <span>echo</span> <span>'文件型态是:'</span>.getFileType($fileName).<span>'<br/>'</span>;</span>
登录后复制
<span id="lnum26">  26:</span><span>     <span>/*文件大小,转换单位*/</span></span>
登录后复制
<span id="lnum27">  27:</span><span>     <span>echo</span> <span>'文件大小是:'</span>.getFileSize(filesize($fileName)).<span>'<br/>'</span>;</span>
登录后复制
<span id="lnum28">  28:</span><span>     <span>/*文件是否可读*/</span></span>
登录后复制
<span id="lnum29">  29:</span><span>     <span>if</span>(is_readable($fileName))</span>
登录后复制
<span id="lnum30">  30:</span><span>     {</span>
登录后复制
<span id="lnum31">  31:</span><span>         <span>echo</span> <span>'文件可读<br/>'</span>;</span>
登录后复制
<span id="lnum32">  32:</span><span>     }</span>
登录后复制
登录后复制
<span id="lnum33">  33:</span><span>     <span>/*文件是否可写*/</span></span>
登录后复制
<span id="lnum34">  34:</span><span>     <span>if</span>(is_writable($fileName))</span>
登录后复制
<span id="lnum35">  35:</span><span>     {</span>
登录后复制
<span id="lnum36">  36:</span><span>         <span>echo</span> <span>'文件可写<br/>'</span>;</span>
登录后复制
<span id="lnum37">  37:</span><span>     }</span>
登录后复制
<span id="lnum38">  38:</span><span>     <span>/*文件是否可执行*/</span></span>
登录后复制
<span id="lnum39">  39:</span><span>     <span>if</span>(is_executable($fileName))</span>
登录后复制
<span id="lnum40">  40:</span><span>     {</span>
登录后复制
<span id="lnum41">  41:</span><span>         <span>echo</span> <span>'文件可执行<br/>'</span>;</span>
登录后复制
<span id="lnum42">  42:</span><span>     }</span>
登录后复制
<span id="lnum43">  43:</span>
登录后复制
<span id="lnum44">  44:</span><span>     <span>echo</span> <span>'文件创立时间:'</span>.date(<span>'Y年m月j日'</span>,filectime($fileName)).<span>'<br/>'</span>;</span>
登录后复制
<span id="lnum45">  45:</span><span>     <span>echo</span> <span>'文件最后修改时间:'</span>.date(<span>'Y年m月j日'</span>,filemtime($fileName)).<span>'<br/>'</span>;</span>
登录后复制
<span id="lnum46">  46:</span><span>     <span>echo</span> <span>'文件最后打开时间:'</span>.date(<span>'Y年m月j日'</span>,fileatime($fileName)).<span>'<br/>'</span>;</span>
登录后复制
<span id="lnum47">  47:</span><span> }</span>
登录后复制
<span id="lnum48">  48:</span>
登录后复制
<span id="lnum49">  49:</span><span> <span>/*</span></span>
登录后复制
<span id="lnum50">  50:</span><span> <span>*声明一个函数,返回文件类型</span></span>
登录后复制
<span id="lnum51">  51:</span><span> <span>*@param string $fileName 文件名称</span></span>
登录后复制
<span id="lnum52">  52:</span><span> <span>*/</span></span>
登录后复制
<span id="lnum53">  53:</span><span> <span>function</span> getFileType($fileName)</span>
登录后复制
<span id="lnum54">  54:</span><span> {</span>
登录后复制
<span id="lnum55">  55:</span><span>     $type = <span>''</span>;</span>
登录后复制
<span id="lnum56">  56:</span><span>     <span>switch</span>(filetype($fileName))</span>
登录后复制
<span id="lnum57">  57:</span><span>     {</span>
登录后复制
<span id="lnum58">  58:</span><span>         <span>case</span> <span>'file'</span>:$type .= <span>'普通文件'</span>;<span>break</span>;</span>
登录后复制
<span id="lnum59">  59:</span><span>         <span>case</span> <span>'dir'</span>:$type .= <span>'目录文件'</span>;<span>break</span>;</span>
登录后复制
<span id="lnum60">  60:</span><span>         <span>case</span> <span>'block'</span>:$type .= <span>'块设备文件'</span>;<span>break</span>;</span>
登录后复制
<span id="lnum61">  61:</span><span>         <span>case</span> <span>'char'</span>:$type .= <span>'字符设备文件'</span>;<span>break</span>;</span>
登录后复制
<span id="lnum62">  62:</span><span>         <span>case</span> <span>'filo'</span>:$type .= <span>'管道文件'</span>;<span>break</span>;</span>
登录后复制
<span id="lnum63">  63:</span><span>         <span>case</span> <span>'link'</span>:$type .= <span>'符号链接'</span>;<span>break</span>;</span>
登录后复制
<span id="lnum64">  64:</span><span>         <span>case</span> <span>'unknown'</span>:$type .= <span>'未知文件'</span>;<span>break</span>;</span>
登录后复制
<span id="lnum65">  65:</span><span>         <span>default</span>:</span>
登录后复制
<span id="lnum66">  66:</span><span>     }</span>
登录后复制
<span id="lnum67">  67:</span><span>     <span>return</span> $type;</span>
登录后复制
<span id="lnum68">  68:</span><span> }</span>
登录后复制
<span id="lnum69">  69:</span>
登录后复制
<span id="lnum70">  70:</span><span> <span>/*</span></span>
登录后复制
<span id="lnum71">  71:</span><span> <span>*声明一个函数,返回文件大小</span></span>
登录后复制
<span id="lnum72">  72:</span><span> <span>*@param int $bytes 文件字节数</span></span>
登录后复制
<span id="lnum73">  73:</span><span> <span>*/</span></span>
登录后复制
<span id="lnum74">  74:</span><span> <span>function</span> getFileSize($bytes)</span>
登录后复制
<span id="lnum75">  75:</span><span> {</span>
登录后复制
<span id="lnum76">  76:</span><span>     <span>if</span>($bytes >= pow(2,40))</span>
登录后复制
<span id="lnum77">  77:</span><span>     {</span>
登录后复制
<span id="lnum78">  78:</span><span>         $<span>return</span> = round($bytes / pow(1024,4),2);</span>
登录后复制
<span id="lnum79">  79:</span><span>         $suffix = <span>'TB'</span>;</span>
登录后复制
<span id="lnum80">  80:</span><span>     }</span>
登录后复制
<span id="lnum81">  81:</span><span>     <span>else</span> <span>if</span>($bytes >= pow(2,30))</span>
登录后复制
<span id="lnum82">  82:</span><span>     {</span>
登录后复制
<span id="lnum83">  83:</span><span>         $<span>return</span> = round($bytes / pow(1024,3),2);</span>
登录后复制
<span id="lnum84">  84:</span><span>         $suffix = <span>'GB'</span>;</span>
登录后复制
<span id="lnum85">  85:</span><span>     }</span>
登录后复制
<span id="lnum86">  86:</span><span>     <span>else</span> <span>if</span>($bytes >= pow(2,20))</span>
登录后复制
<span id="lnum87">  87:</span><span>     {</span>
登录后复制
<span id="lnum88">  88:</span><span>         $<span>return</span> = round($bytes / pow(1024,2),2);</span>
登录后复制
<span id="lnum89">  89:</span><span>         $suffix = <span>'MB'</span>;</span>
登录后复制
<span id="lnum90">  90:</span><span>     }</span>
登录后复制
<span id="lnum91">  91:</span><span>     <span>else</span> <span>if</span>($bytes >= pow(2,10))</span>
登录后复制
<span id="lnum92">  92:</span><span>     {</span>
登录后复制
<span id="lnum93">  93:</span><span>         $<span>return</span> = round($bytes / pow(1024,1),2);</span>
登录后复制
<span id="lnum94">  94:</span><span>         $suffix = <span>'KB'</span>;</span>
登录后复制
<span id="lnum95">  95:</span><span>     }</span>
登录后复制
<span id="lnum96">  96:</span><span>     <span>else</span></span>
登录后复制
<span id="lnum97">  97:</span><span>     {</span>
登录后复制
<span id="lnum98">  98:</span><span>         $<span>return</span> = $bytes;</span>
登录后复制
<span id="lnum99">  99:</span><span>         $suffix = <span>'B'</span>;</span>
登录后复制
<span id="lnum100"> 100:</span><span>     }</span>
登录后复制
<span id="lnum101"> 101:</span><span>     <span>return</span> $<span>return</span>.<span>" "</span>.$suffix;</span>
登录后复制
<span id="lnum102"> 102:</span><span> }</span>
登录后复制
<span id="lnum103"> 103:</span>
登录后复制
<span id="lnum104"> 104:</span><span> <span>/*调用函数,传入test目录下的test.txt文件*/</span></span>
登录后复制
<span id="lnum105"> 105:</span><span> getFilePro(<span>'./test/div.html'</span>);</span>
登录后复制
<span id="lnum106"> 106:</span><span> ?></span>
登录后复制
结果:


二、目录的操作

目录的操作有:遍历目录、删除、复制、大小统计等

1、遍历目录

<span id="lnum1">   1:</span><span> <span>/*</span></span>
登录后复制
登录后复制
登录后复制
登录后复制
<span id="lnum2">   2:</span><span> <span>*遍历目录</span></span>
登录后复制
<span id="lnum3">   3:</span><span> <span>*@param string $dirName 目录名</span></span>
登录后复制
登录后复制
登录后复制
<span id="lnum4">   4:</span><span> <span>*/</span></span>
登录后复制
登录后复制
<span id="lnum5">   5:</span><span> <span>function</span> findDir($dirName)</span>
登录后复制
<span id="lnum6">   6:</span><span> {</span>
登录后复制
登录后复制
<span id="lnum7">   7:</span><span>     $num  = 0;  <span>/*统计子文件个数*/</span></span>
登录后复制
<span id="lnum8">   8:</span><span>     $dir_handle = opendir($dirName);  <span>/*打开目录*/</span></span>
登录后复制
<span id="lnum9">   9:</span><span>     <span>/*输出目录文件*/</span></span>
登录后复制
<span id="lnum10">  10:</span><span>     <span>echo</span> <span>'<table border="0" align="center" width="600" cellspacing="0" cellpadding="0">'</span>;</span>
登录后复制
<span id="lnum11">  11:</span><span>     <span>echo</span> <span>'<caption><h2>目录'</span>.$dirName.<span>'下的文件</h2></caption>'</span>;</span>
登录后复制
<span id="lnum12">  12:</span><span>     <span>echo</span> <span>'<tr align="left" bgcolor="#cccccc"'</span>;</span>
登录后复制
<span id="lnum13">  13:</span><span>     <span>echo</span> <span>'<th>文件名</th><th>文件大小</th><th>文件类型</th><th>修改时间</th></tr>'</span>;</span>
登录后复制
<span id="lnum14">  14:</span>
登录后复制
<span id="lnum15">  15:</span><span>     <span>while</span>($file = readdir($dir_handle))</span>
登录后复制
<span id="lnum16">  16:</span><span>     {</span>
登录后复制
登录后复制
<span id="lnum17">  17:</span><span>         $dirFile = $dirName.<span>'/'</span>.$file;</span>
登录后复制
<span id="lnum18">  18:</span><span>         $bgcolor = $num++%2==0?<span>'#ffffff'</span>:<span>'#cccccc'</span>;</span>
登录后复制
<span id="lnum19">  19:</span><span>         <span>echo</span> <span>'<tr bgcolor='</span>.$bgcolor.<span>'>'</span>;</span>
登录后复制
<span id="lnum20">  20:</span><span>         <span>echo</span> <span>'<td>'</span>.$file.<span>'</td>'</span>;</span>
登录后复制
<span id="lnum21">  21:</span><span>         <span>echo</span> <span>'<td>'</span>.filesize($dirFile).<span>'</td>'</span>;</span>
登录后复制
<span id="lnum22">  22:</span><span>         <span>echo</span> <span>'<td>'</span>.filetype($dirFile).<span>'</td>'</span>;</span>
登录后复制
<span id="lnum23">  23:</span><span>         <span>echo</span> <span>'<td>'</span>.date(<span>'Y/n/t'</span>,filemtime($dirFile)).<span>'</td>'</span>;</span>
登录后复制
<span id="lnum24">  24:</span><span>         <span>echo</span> <span>'</tr>'</span>;</span>
登录后复制
<span id="lnum25">  25:</span><span>     }</span>
登录后复制
<span id="lnum26">  26:</span><span>     <span>echo</span> <span>"</table>"</span>;</span>
登录后复制
<span id="lnum27">  27:</span><span>     closedir($dir_handle);  <span>/*关闭目录*/</span></span>
登录后复制
<span id="lnum28">  28:</span><span>     <span>echo</span> <span>"在<b>"</span>.$dirName.<span>"</b>目录下共有<b>"</span>.$num.<span>'</b>个子文件'</span>;</span>
登录后复制
<span id="lnum29">  29:</span><span> }</span>
登录后复制
<span id="lnum30">  30:</span><span> <span>/*传递当前目录下的test目录*/</span></span>
登录后复制
<span id="lnum31">  31:</span><span> findDir(<span>'./test'</span>);</span>
登录后复制

结果



2、统计目录大小

<span id="lnum1">   1:</span><span> <span>/*</span></span>
登录后复制
登录后复制
登录后复制
登录后复制
<span id="lnum2">   2:</span><span> <span>*统计目录大小</span></span>
登录后复制
<span id="lnum3">   3:</span><span> <span>*@param string $dirName 目录名</span></span>
登录后复制
登录后复制
登录后复制
<span id="lnum4">   4:</span><span> <span>*@return double</span></span>
登录后复制
<span id="lnum5">   5:</span><span> <span>*/</span></span>
登录后复制
登录后复制
<span id="lnum6">   6:</span>
登录后复制
<span id="lnum7">   7:</span><span> <span>function</span> dirSize($dirName)</span>
登录后复制
<span id="lnum8">   8:</span><span> {</span>
登录后复制
登录后复制
<span id="lnum9">   9:</span><span>     $dir_size = 0;</span>
登录后复制
<span id="lnum10">  10:</span><span>     <span>if</span>($dir_handle = @opendir($dirName))</span>
登录后复制
<span id="lnum11">  11:</span><span>     {</span>
登录后复制
<span id="lnum12">  12:</span><span>         <span>while</span> ($fileName = readdir($dir_handle))</span>
登录后复制
<span id="lnum13">  13:</span><span>         {</span>
登录后复制
<span id="lnum14">  14:</span>              /*排除两个特殊目录*/
登录后复制
<span id="lnum15">  15:</span><span>             <span>if</span>($fileName != <span>'.'</span> && $fileName != <span>'..'</span>)</span>
登录后复制
<span id="lnum16">  16:</span><span>             {</span>
登录后复制
<span id="lnum17">  17:</span><span>                 $subFile = $dirName.<span>'/'</span>.$fileName;</span>
登录后复制
<span id="lnum18">  18:</span><span>                 <span>if</span>(is_file($subFile))</span>
登录后复制
<span id="lnum19">  19:</span><span>                 {</span>
登录后复制
<span id="lnum20">  20:</span><span>                     $dir_size += filesize($subFile);</span>
登录后复制
<span id="lnum21">  21:</span><span>                 }</span>
登录后复制
<span id="lnum22">  22:</span><span>                 <span>if</span>(is_dir($subFile))</span>
登录后复制
<span id="lnum23">  23:</span><span>                 {</span>
登录后复制
<span id="lnum24">  24:</span><span>                     $dir_size += dirSize($subFile);</span>
登录后复制
<span id="lnum25">  25:</span><span>                 }</span>
登录后复制
<span id="lnum26">  26:</span><span>             }</span>
登录后复制
<span id="lnum27">  27:</span><span>         }</span>
登录后复制
<span id="lnum28">  28:</span><span>         closedir($dir_handle);</span>
登录后复制
<span id="lnum29">  29:</span><span>         <span>return</span> $dir_size;</span>
登录后复制
<span id="lnum30">  30:</span><span>     }</span>
登录后复制
<span id="lnum31">  31:</span><span> }</span>
登录后复制
<span id="lnum32">  32:</span><span> <span>/*传递当前目录下的test目录*/</span></span>
登录后复制
<span id="lnum33">  33:</span><span> $dir_size = dirSize(<span>'./test'</span>);</span>
登录后复制
<span id="lnum34">  34:</span><span> <span>echo</span> <span>'./test目录文件大小是:'</span>.round($dir_size / pow(1024,1),2).<span>'KB'</span>;</span>
登录后复制

结果



3、删除目录

<span id="lnum1">   1:</span><span> <span>/*</span></span>
登录后复制
登录后复制
登录后复制
登录后复制
<span id="lnum2">   2:</span><span> <span>*删除目录</span></span>
登录后复制
<span id="lnum3">   3:</span><span> <span>*@param string $dirName 目录名</span></span>
登录后复制
登录后复制
登录后复制
<span id="lnum4">   4:</span><span> <span>*/</span></span>
登录后复制
登录后复制
<span id="lnum5">   5:</span><span> <span>function</span> delDir($dirName)</span>
登录后复制
<span id="lnum6">   6:</span><span> {</span>
登录后复制
登录后复制
<span id="lnum7">   7:</span><span>     <span>/*php中的mkdir函数就可以创建目录*/</span></span>
登录后复制
<span id="lnum8">   8:</span><span>     <span>if</span>(file_exists($dirName))</span>
登录后复制
<span id="lnum9">   9:</span><span>     {</span>
登录后复制
登录后复制
<span id="lnum10">  10:</span><span>         <span>if</span>($dir_handle = @opendir($dirName))</span>
登录后复制
<span id="lnum11">  11:</span><span>         {</span>
登录后复制
<span id="lnum12">  12:</span><span>             <span>while</span> ($fileName = readdir($dir_handle))</span>
登录后复制
<span id="lnum13">  13:</span><span>             {</span>
登录后复制
<span id="lnum14">  14:</span>                  /*排除两个特殊目录*/
登录后复制
<span id="lnum15">  15:</span><span>                 <span>if</span>($fileName != <span>'.'</span> && $fileName != <span>'..'</span>)</span>
登录后复制
<span id="lnum16">  16:</span><span>                 {</span>
登录后复制
<span id="lnum17">  17:</span><span>                     $subFile = $dirName.<span>'/'</span>.$fileName;</span>
登录后复制
<span id="lnum18">  18:</span><span>                     <span>if</span>(is_file($subFile))</span>
登录后复制
<span id="lnum19">  19:</span><span>                     {</span>
登录后复制
<span id="lnum20">  20:</span><span>                         unlink($subFile);</span>
登录后复制
<span id="lnum21">  21:</span><span>                     }</span>
登录后复制
<span id="lnum22">  22:</span><span>                     <span>if</span>(is_dir($subFile))</span>
登录后复制
<span id="lnum23">  23:</span><span>                     {</span>
登录后复制
<span id="lnum24">  24:</span><span>                         delDir($subFile);</span>
登录后复制
<span id="lnum25">  25:</span><span>                     }</span>
登录后复制
<span id="lnum26">  26:</span><span>                 }</span>
登录后复制
<span id="lnum27">  27:</span><span>             }</span>
登录后复制
<span id="lnum28">  28:</span><span>             closedir($dir_handle);</span>
登录后复制
<span id="lnum29">  29:</span><span>             rmdir($dirName);</span>
登录后复制
<span id="lnum30">  30:</span><span>             <span>return</span> $dirName.<span>'目录已经删除'</span>;</span>
登录后复制
<span id="lnum31">  31:</span><span>         }</span>
登录后复制
<span id="lnum32">  32:</span><span>     }</span>
登录后复制
登录后复制
<span id="lnum33">  33:</span><span> }</span>
登录后复制
<span id="lnum34">  34:</span><span> <span>/*传递test目录的副本test1*/</span></span>
登录后复制
<span id="lnum35">  35:</span><span> <span>echo</span> delDir(<span>'./test1'</span>);</span>
登录后复制

删除成功的提示信息



4、复制目录

<span id="lnum1">   1:</span><span> <span>/*</span></span>
登录后复制
登录后复制
登录后复制
登录后复制
<span id="lnum2">   2:</span><span> <span>*复制目录</span></span>
登录后复制
<span id="lnum3">   3:</span><span> <span>*@param string $dirSrc 原目录名</span></span>
登录后复制
<span id="lnum4">   4:</span><span> <span>*@param string $dirTo 目标目录名</span></span>
登录后复制
<span id="lnum5">   5:</span><span> <span>*/</span></span>
登录后复制
登录后复制
<span id="lnum6">   6:</span> function copyDir($dirSrc,$dirTo)
登录后复制
<span id="lnum7">   7:</span><span> {</span>
登录后复制
<span id="lnum8">   8:</span><span>     <span>if</span>(is_file($dirTo))</span>
登录后复制
<span id="lnum9">   9:</span><span>     {</span>
登录后复制
登录后复制
<span id="lnum10">  10:</span><span>         <span>echo</span> <span>'目标目录不能创建'</span>;<span>/*目标不是一个*/</span></span>
登录后复制
<span id="lnum11">  11:</span><span>         <span>return</span>;</span>
登录后复制
<span id="lnum12">  12:</span><span>     }</span>
登录后复制
<span id="lnum13">  13:</span><span>     <span>if</span>(!file_exists($dirTo))</span>
登录后复制
<span id="lnum14">  14:</span>     {
登录后复制
<span id="lnum15">  15:</span><span>         <span>/*目录不存在则创建*/</span></span>
登录后复制
<span id="lnum16">  16:</span><span>         mkdir($dirTo);</span>
登录后复制
<span id="lnum17">  17:</span><span>     }</span>
登录后复制
<span id="lnum18">  18:</span><span>     <span>if</span>($dir_handle = @opendir($dirSrc))</span>
登录后复制
<span id="lnum19">  19:</span><span>     {</span>
登录后复制
<span id="lnum20">  20:</span><span>         <span>while</span> ($fileName = readdir($dir_handle))</span>
登录后复制
<span id="lnum21">  21:</span><span>         {</span>
登录后复制
<span id="lnum22">  22:</span><span>              <span>/*排除两个特殊目录*/</span></span>
登录后复制
<span id="lnum23">  23:</span><span>             <span>if</span>($fileName != <span>'.'</span> && $fileName != <span>'..'</span>)</span>
登录后复制
<span id="lnum24">  24:</span><span>             {</span>
登录后复制
<span id="lnum25">  25:</span><span>                 $subSrcFile = $dirSrc.<span>'/'</span>.$fileName;</span>
登录后复制
<span id="lnum26">  26:</span><span>                 $subToFile = $dirTo.<span>'/'</span>.$fileName;</span>
登录后复制
<span id="lnum27">  27:</span><span>                 <span>if</span>(is_file($subSrcFile))</span>
登录后复制
<span id="lnum28">  28:</span><span>                 {</span>
登录后复制
<span id="lnum29">  29:</span><span>                     copy($subSrcFile,$subToFile);</span>
登录后复制
<span id="lnum30">  30:</span><span>                 }</span>
登录后复制
<span id="lnum31">  31:</span><span>                 <span>if</span>(is_dir($subSrcFile))</span>
登录后复制
<span id="lnum32">  32:</span><span>                 {</span>
登录后复制
<span id="lnum33">  33:</span><span>                     copyDir($subSrcFile,$subToFile);</span>
登录后复制
<span id="lnum34">  34:</span><span>                 }</span>
登录后复制
<span id="lnum35">  35:</span><span>             }</span>
登录后复制
<span id="lnum36">  36:</span><span>         }</span>
登录后复制
<span id="lnum37">  37:</span><span>         closedir($dir_handle);</span>
登录后复制
<span id="lnum38">  38:</span><span>         <span>return</span> $dirSrc.<span>'目录已经复制到'</span>.$dirTo.<span>'目录'</span>;</span>
登录后复制
<span id="lnum39">  39:</span><span>     }</span>
登录后复制
<span id="lnum40">  40:</span><span> }</span>
登录后复制
<span id="lnum41">  41:</span><span> <span>echo</span> copyDir(<span>'./test'</span>,<span>'../testcopy'</span>);</span>
登录后复制

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板