Laravel 下载大文件最终未找到
Laravel downloading large file end up not found
我正在开发一个销售文件和所有下载文件或超过 500Mb 的电子商务网站。所以为了更好的保护,我将所有文件存储在存储文件夹中并像这样创建磁盘
'academy' => [
'driver' => 'local',
'root' => storage_path('app/academy'),
],
所以我提到所有文件大小都超过 500Mb,所以我不能简单地使用 Responce::download
(两次下载后 === 服务器关闭内存填满)
所以我在 Whosebug 中搜索并找到这个答案 #1 and 所以我使用此代码下载文件:
$fs = Storage::disk('academy')->getDriver();
$fileName = $file; //-> path to file
$metaData = $fs->getMetadata($fileName);
$stream = $fs->readStream($fileName);
if (ob_get_level()) ob_end_clean();
return response()->stream(
function () use ($stream) {
while(ob_end_flush());
fpassthru($stream);
},
200,
[
'Content-Type' => $metaData['type'],
'Content-disposition' => 'attachment; filename="' . $metaData['path'] . '"',
]);
在 运行 收到此错误后
"File not found at path: D:/laragon/www/store/storage/app/academy/7FrggloHEjjc72rVJO1jPdF10nJL57MBMBvfwpYE.zip"
在此文件上
D:\laragon\www\store\vendor\league\flysystem\src\Filesystem.php Line 388
public function assertPresent($path)
{
if ($this->config->get('disable_asserts', false) === false && ! $this->has($path)) {
throw new FileNotFoundException($path);
}
}
The funny thing about this error is the path that returns if put in windows explorer it open the zip file (Path is correct)
并且已经使用 php artisan storage:link
我不知道这是错误还是我对 laravel 框架中存储的知识不足:
当你通过存储保存文件时,return 文件的路径,所以当我将此路径提供给上面的代码时,我将该路径保存在我的数据库中 return 那个错误就这样消失了无处我决定只发送没有路径的文件名并且简单的代码工作。
希望这个回答对大家有所帮助!
我正在开发一个销售文件和所有下载文件或超过 500Mb 的电子商务网站。所以为了更好的保护,我将所有文件存储在存储文件夹中并像这样创建磁盘
'academy' => [
'driver' => 'local',
'root' => storage_path('app/academy'),
],
所以我提到所有文件大小都超过 500Mb,所以我不能简单地使用 Responce::download
(两次下载后 === 服务器关闭内存填满)
所以我在 Whosebug 中搜索并找到这个答案 #1 and
$fs = Storage::disk('academy')->getDriver();
$fileName = $file; //-> path to file
$metaData = $fs->getMetadata($fileName);
$stream = $fs->readStream($fileName);
if (ob_get_level()) ob_end_clean();
return response()->stream(
function () use ($stream) {
while(ob_end_flush());
fpassthru($stream);
},
200,
[
'Content-Type' => $metaData['type'],
'Content-disposition' => 'attachment; filename="' . $metaData['path'] . '"',
]);
在 运行 收到此错误后
"File not found at path: D:/laragon/www/store/storage/app/academy/7FrggloHEjjc72rVJO1jPdF10nJL57MBMBvfwpYE.zip"
在此文件上
D:\laragon\www\store\vendor\league\flysystem\src\Filesystem.php Line 388
public function assertPresent($path)
{
if ($this->config->get('disable_asserts', false) === false && ! $this->has($path)) {
throw new FileNotFoundException($path);
}
}
The funny thing about this error is the path that returns if put in windows explorer it open the zip file (Path is correct)
并且已经使用 php artisan storage:link
我不知道这是错误还是我对 laravel 框架中存储的知识不足:
当你通过存储保存文件时,return 文件的路径,所以当我将此路径提供给上面的代码时,我将该路径保存在我的数据库中 return 那个错误就这样消失了无处我决定只发送没有路径的文件名并且简单的代码工作。
希望这个回答对大家有所帮助!