簡體   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