<bdo id='f60sv'></bdo><ul id='f60sv'></ul>
    1. <tfoot id='f60sv'></tfoot>
    2. <small id='f60sv'></small><noframes id='f60sv'>

      <i id='f60sv'><tr id='f60sv'><dt id='f60sv'><q id='f60sv'><span id='f60sv'><b id='f60sv'><form id='f60sv'><ins id='f60sv'></ins><ul id='f60sv'></ul><sub id='f60sv'></sub></form><legend id='f60sv'></legend><bdo id='f60sv'><pre id='f60sv'><center id='f60sv'></center></pre></bdo></b><th id='f60sv'></th></span></q></dt></tr></i><div id='f60sv'><tfoot id='f60sv'></tfoot><dl id='f60sv'><fieldset id='f60sv'></fieldset></dl></div>
    3. <legend id='f60sv'><style id='f60sv'><dir id='f60sv'><q id='f60sv'></q></dir></style></legend>

        如何在php中获取目录中的最新文件

        How to get the newest file in a directory in php(如何在php中获取目录中的最新文件)
        1. <tfoot id='XTyJR'></tfoot>

            <legend id='XTyJR'><style id='XTyJR'><dir id='XTyJR'><q id='XTyJR'></q></dir></style></legend>
              • <bdo id='XTyJR'></bdo><ul id='XTyJR'></ul>

                <small id='XTyJR'></small><noframes id='XTyJR'>

                  <i id='XTyJR'><tr id='XTyJR'><dt id='XTyJR'><q id='XTyJR'><span id='XTyJR'><b id='XTyJR'><form id='XTyJR'><ins id='XTyJR'></ins><ul id='XTyJR'></ul><sub id='XTyJR'></sub></form><legend id='XTyJR'></legend><bdo id='XTyJR'><pre id='XTyJR'><center id='XTyJR'></center></pre></bdo></b><th id='XTyJR'></th></span></q></dt></tr></i><div id='XTyJR'><tfoot id='XTyJR'></tfoot><dl id='XTyJR'><fieldset id='XTyJR'></fieldset></dl></div>
                    <tbody id='XTyJR'></tbody>
                  本文介绍了如何在php中获取目录中的最新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以我有这个处理 CSV 文件的应用程序.我有一行代码来加载文件.

                  So I have this app that processes CSV files. I have a line of code to load the file.

                  $myFile = "data/FrontlineSMS_Message_Export_20120721.csv";  //The name of the CSV file
                  $fh = fopen($myFile, 'r');                             //Open the file
                  

                  我想找到一种方法来查看 data 目录并获取最新的文件(它们都有日期标签,因此它们在 data) 并将名称设置为等于 $myFile.

                  I would like to find a way in which I could look in the data directory and get the newest file (they all have date tags so they would be in order inside of data) and set the name equal to $myFile.

                  我真的找不到和理解 php 目录的文档,所以任何有用的资源也将不胜感激.谢谢.

                  I really couldn't find and understand the documentation of php directories so any helpful resources would be appreciated as well. Thank you.

                  推荐答案

                  这是使用 scandir 的尝试,假设目录中仅有的文件具有带时间戳的文件名:

                  Here's an attempt using scandir, assuming the only files in the directory have timestamped filenames:

                  $files = scandir('data', SCANDIR_SORT_DESCENDING);
                  $newest_file = $files[0];
                  

                  我们首先按降序列出目录中的所有文件,然后,该列表中的第一个文件具有最大"文件名——因此具有最大的时间戳值——因此是最新的.

                  We first list all files in the directory in descending order, then, whichever one is first in that list has the "greatest" filename — and therefore the greatest timestamp value — and is therefore the newest.

                  请注意,scandir 是在 PHP 5 中添加的,但 其文档页面 显示了如何在 PHP 4 中实现该行为.

                  Note that scandir was added in PHP 5, but its documentation page shows how to implement that behavior in PHP 4.

                  这篇关于如何在php中获取目录中的最新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Proxy Authentication Required with cURL(cURL 需要代理身份验证)
                  How to use a SOCKS 5 proxy with cURL?(如何使用带有 cURL 的 SOCKS 5 代理?)
                  How to use HTTP_X_FORWARDED_FOR properly?(如何正确使用 HTTP_X_FORWARDED_FOR?)
                  file_get_contents behind a proxy?(代理后面的 file_get_contents ?)
                  pecl install cassandra throws: quot;error: Unable to load libcassandraquot;(pecl install cassandra 抛出:“错误:无法加载 libcassandra)
                  Installing php datastax driver on ubuntu(在 ubuntu 上安装 php datastax 驱动)
                    <legend id='KAxlz'><style id='KAxlz'><dir id='KAxlz'><q id='KAxlz'></q></dir></style></legend>

                        • <i id='KAxlz'><tr id='KAxlz'><dt id='KAxlz'><q id='KAxlz'><span id='KAxlz'><b id='KAxlz'><form id='KAxlz'><ins id='KAxlz'></ins><ul id='KAxlz'></ul><sub id='KAxlz'></sub></form><legend id='KAxlz'></legend><bdo id='KAxlz'><pre id='KAxlz'><center id='KAxlz'></center></pre></bdo></b><th id='KAxlz'></th></span></q></dt></tr></i><div id='KAxlz'><tfoot id='KAxlz'></tfoot><dl id='KAxlz'><fieldset id='KAxlz'></fieldset></dl></div>
                            <bdo id='KAxlz'></bdo><ul id='KAxlz'></ul>
                              <tbody id='KAxlz'></tbody>

                            <small id='KAxlz'></small><noframes id='KAxlz'>

                            <tfoot id='KAxlz'></tfoot>