两个方案,第一个,php读取文件并输出,在Laravel中代码大致如下 // 控制器 // https://github.com/shellus/shcms/blob/v2.0.0/app/Http/Controllers/FileController.php class FileController extends Controller { public function show($id){ return File::findOrFail($id) -> downResponse(); } } // Model https://github.com/shellus/shcms/blob/v2.0.0/app/File.php public function downResponse(){ return new BinaryFileResponse($this -> downToLocal()); } public function downToLocal(){ $temp_path = tempnam(sys_get_temp_dir(), $this->id); $is_success = file_put_contents($temp_path, \Storage::disk('public')->get($this -> full_path)); return $temp_path; } 第二个,使用Linux ln命令建立storage文件夹软链接public文件夹,但是这样做与直接将文件存放在public没有区别。
两个方案,第一个,php读取文件并输出,在Laravel中代码大致如下
第二个,使用Linux ln命令建立storage文件夹软链接public文件夹,但是这样做与直接将文件存放在public没有区别。