如何获取远程文件夹 PHP 中的最新文件?
How to get newest file in remote folder PHP?
我尝试获取文件夹的最新文件,但它不起作用。
我的文件夹有一个 URL 和 html://... 这可能是问题所在吗?
这是我测试的...
谢谢
$files = scandir('http://wwww.site.com/myfolder', SCANDIR_SORT_DESCENDING);
$newest_file = $files[0];
或
$path = "http://wwww.site.com/myfolder";
$latest_ctime = 0;
$latest_filename = '';
$d = dir($path);
while (false !== ($entry = $d->read())) {
$filepath = "{$path}/{$entry}";
// could do also other checks than just checking whether the entry is a file
if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
$latest_ctime = filectime($filepath);
$latest_filename = $entry;
}
}
您需要替换此代码:
$path = "http://wwww.site.com/myfolder";
有了这个:
$path = "myfolder";
我尝试获取文件夹的最新文件,但它不起作用。 我的文件夹有一个 URL 和 html://... 这可能是问题所在吗? 这是我测试的... 谢谢
$files = scandir('http://wwww.site.com/myfolder', SCANDIR_SORT_DESCENDING);
$newest_file = $files[0];
或
$path = "http://wwww.site.com/myfolder";
$latest_ctime = 0;
$latest_filename = '';
$d = dir($path);
while (false !== ($entry = $d->read())) {
$filepath = "{$path}/{$entry}";
// could do also other checks than just checking whether the entry is a file
if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
$latest_ctime = filectime($filepath);
$latest_filename = $entry;
}
}
您需要替换此代码:
$path = "http://wwww.site.com/myfolder";
有了这个:
$path = "myfolder";