简体   繁体   English

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

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

I have a list of files in a directory of some local path with names like APX-904-118000945-NMR-ETC with different extensions.我在某个本地路径的目录中有一个文件列表,其名称类似于具有不同扩展名的APX-904-118000945-NMR-ETC For every file name a code exists, in this filename 118000945 , using which i want to search and download that file in php.对于每个文件名,都存在一个代码,在这个文件名118000945 ,我想使用它在 php 中搜索和下载该文件。

I am able to pass the code ie, 118000945 but unable to search for it and download with some piece of code got from web.我能够传递代码, ie, 118000945但无法搜索它并使用从网络获得的一些代码进行下载。

Could you help me out in writing a php script for this?你能帮我写一个 php 脚本吗?

Consider using the symfony finder component考虑使用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