繁体   English   中英

在目录中的文件名中搜索php关键字并下载

[英]Php keyword search in file name in a directory and download

我在某个本地路径的目录中有一个文件列表,其名称类似于具有不同扩展名的APX-904-118000945-NMR-ETC 对于每个文件名,都存在一个代码,在这个文件名118000945 ,我想使用它在 php 中搜索和下载该文件。

我能够传递代码, ie, 118000945但无法搜索它并使用从网络获得的一些代码进行下载。

你能帮我写一个 php 脚本吗?

考虑使用symfony finder 组件

$idToFind = '118000945';

$finder = new Finder();
$finder->files()
    ->in('/path/to/dir')
    ->name(sprintf('*%s*', $idToFind));

foreach ($finder as $file) {
    $absoluteFilePath = $file->getRealPath();
    $fileNameWithExtension = $file->getRelativePathname();

    // ...
}


暂无
暂无

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

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