Why does this code always give me an error "Illegal string offset 'list_img'"? Where have I made a mistake?
$dir = scandir($route);
for ($img = 0; $img < count($dir); $img++) {
if ($dir[$img] == "." || $dir[$img] == "..") {
continue;
}
$type = pathinfo($route . '/' . $dir[$img], PATHINFO_EXTENSION);
$data = file_get_contents($route . '/' . $dir[$img]);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
array_push($list_dir, ['title' => $dir[$img], 'code' => $base64]);
}
$data['list_img'] = $list_dir;