简体   繁体   English

无法打开流:没有这样的文件或目录与php - scandir

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

I'm using Laravel 5.1 In folder /public/download I have many .htm pages I need to get so I write: 我正在使用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;
}
}

but I got error: 但是我得到了错误:

ErrorException in AdminController.php line 133: file_get_contents(1742-wine-bar-1.htm): failed to open stream: No such file or directory AdminController.php第133行中的ErrorException:file_get_contents(1742-wine-bar-1.htm):无法打开流:没有这样的文件或目录 在此输入图像描述 I also try: 我也尝试:

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

我解决了我的问题:

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

I think you should use 我想你应该用

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

because here in $html variable your have only a filename, but you must include a directory path in function file_get_contents() 因为在$ html变量中你只有一个文件名,但你必须在函数file_get_contents()包含一个目录路径

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

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