我想访问 linux 服务器中 var 文件夹之外的文件以及 /var/www/html 中的 codeigniter-3 项目。
以及 /data 文件夹内的文件。
“/data/admin_assets/upload_files/Photos/nala/start_photo.jpg”是存储在数据库中的路径,因此当我访问此网址时,我收到 404-未找到错误
您可以使用 PHP 的 readfile 读取文件并返回浏览器。 可以这样使用一个例子:
<?php
$file = "/data/admin_assets/upload_files/Photos/nala/start_photo.jpg";
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
?>
并确保设置权限,以便网络服务器可以访问该目录:
data/admin_assets/upload_files/Photos/nala/