簡體   English   中英

無法打開流:沒有這樣的文件或目錄與php - scandir

[英]Failed to open stream: No such file or directory with php - scandir

我正在使用Laravel 5.1在文件夾/公共/下載中我有很多.htm頁面我需要得到所以我寫道:

public function scraper() {

 $path = 'downloads/';
$files = scandir($path);
foreach ($files as $k => $file) {
    if ($k < 2) continue;
  $html = file_get_contents($file);

//parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);

$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("//div[@class='merchant-links']/a/@href");

echo $hrefs;
}
}

但是我得到了錯誤:

AdminController.php第133行中的ErrorException:file_get_contents(1742-wine-bar-1.htm):無法打開流:沒有這樣的文件或目錄 在此輸入圖像描述 我也嘗試:

 $path = 'C:/wamp/www/mavis/public/downloads/';

我解決了我的問題:

$files = glob('downloads/*.{htm}', GLOB_BRACE);

我想你應該用

$html = file_get_contents($path.$file);

因為在$ html變量中你只有一個文件名,但你必須在函數file_get_contents()包含一個目錄路徑

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM