I have a list of files in a directory of some local path with names like APX-904-118000945-NMR-ETC
with different extensions. For every file name a code exists, in this filename 118000945
, using which i want to search and download that file in 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.
Could you help me out in writing a php script for this?
Consider using the symfony finder component
$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();
// ...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.