简体   繁体   English

如何在远程文件夹PHP中获取最新文件?

[英]How to get newest file in remote folder PHP?

I try to get the most recent file of a folder but it does not work. 我尝试获取文件夹的最新文件,但是它不起作用。 My folder has an URL with html://... Can it be the problem ? 我的文件夹的URL带有html:// ...这可能是问题吗? This is what i tested ... thanks 这是我测试过的...谢谢

$files = scandir('http://wwww.site.com/myfolder', SCANDIR_SORT_DESCENDING);
$newest_file = $files[0];

OR 要么

$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;
  }
}

You need to replace this code: 您需要替换以下代码:

$path = "http://wwww.site.com/myfolder";

With this: 有了这个:

$path = "myfolder"; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM