繁体   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