Laravel 错误。无法打开目录:未实现
Laravel error. Failed to open dir: not implemented
我正在尝试使用此脚本从 Laravel 项目的一个文件夹中的所有图片渲染一个画廊。我收到这个错误
ErrorException in ArmadiController.php line 32:
opendir(http://mysite.dev:8000/images): failed to open dir: not
implemented
这是控制器中产生错误的函数。我怎样才能让它工作或做类似的事情?
public function gallery()
{
$data = [];
$folder_path = asset('images');
$num_files = glob($folder_path . "*.{JPG,jpg,gif,png,bmp}", GLOB_BRACE);
$folder = opendir($folder_path);
if ($num_files > 0) {
while (false !== ($file = readdir($folder))) {
$file_path = $folder_path . $file;
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if ($extension == 'jpg' || $extension == 'png' || $extension == 'gif' || $extension == 'bmp') {
$data[] = $file_path;
}
}
} else {
return "the folder was empty !";
}
closedir($folder);
return $data;
}
问题是 opendir() 函数需要本地路径。可以使用 public_path() 而不是 asset() 函数来解决。
我正在尝试使用此脚本从 Laravel 项目的一个文件夹中的所有图片渲染一个画廊。我收到这个错误
ErrorException in ArmadiController.php line 32: opendir(http://mysite.dev:8000/images): failed to open dir: not implemented
这是控制器中产生错误的函数。我怎样才能让它工作或做类似的事情?
public function gallery()
{
$data = [];
$folder_path = asset('images');
$num_files = glob($folder_path . "*.{JPG,jpg,gif,png,bmp}", GLOB_BRACE);
$folder = opendir($folder_path);
if ($num_files > 0) {
while (false !== ($file = readdir($folder))) {
$file_path = $folder_path . $file;
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if ($extension == 'jpg' || $extension == 'png' || $extension == 'gif' || $extension == 'bmp') {
$data[] = $file_path;
}
}
} else {
return "the folder was empty !";
}
closedir($folder);
return $data;
}
问题是 opendir() 函数需要本地路径。可以使用 public_path() 而不是 asset() 函数来解决。