php 按日期列出目录内容
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 按日期列出目录内容相关的知识,希望对你有一定的参考价值。
<span style="color: #000000; font-weight: bold;">function</span> listdir_by_date<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$path</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #0000ff;">$dir</span> = <a href="http://www.php.net/opendir"><span style="color: #000066;">opendir</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$path</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$list</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="color: #b1b100;">while</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$file</span> = <a href="http://www.php.net/readdir"><span style="color: #000066;">readdir</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$dir</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$file</span> != <span style="color: #ff0000;">'.'</span> and <span style="color: #0000ff;">$file</span> != <span style="color: #ff0000;">'..'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #808080; font-style: italic;">// add the filename, to be sure not to</span>
<span style="color: #808080; font-style: italic;">// overwrite a array key</span>
<span style="color: #0000ff;">$ctime</span> = <a href="http://www.php.net/filectime"><span style="color: #000066;">filectime</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$data_path</span> . <span style="color: #0000ff;">$file</span><span style="color: #66cc66;">)</span> . <span style="color: #ff0000;">','</span> . <span style="color: #0000ff;">$file</span>;
<span style="color: #0000ff;">$list</span><span style="color: #66cc66;">[</span><span style="color: #0000ff;">$ctime</span><span style="color: #66cc66;">]</span> = <span style="color: #0000ff;">$file</span>;
<span style="color: #66cc66;">}</span>
<span style="color: #66cc66;">}</span>
<a href="http://www.php.net/closedir"><span style="color: #000066;">closedir</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$dir</span><span style="color: #66cc66;">)</span>;
<a href="http://www.php.net/krsort"><span style="color: #000066;">krsort</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$list</span><span style="color: #66cc66;">)</span>;
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$list</span>;
<span style="color: #66cc66;">}</span>
以上是关于php 按日期列出目录内容的主要内容,如果未能解决你的问题,请参考以下文章