mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-07 18:07:05 +00:00
fix: 没有后缀名无法下载文件的问题
This commit is contained in:
parent
ce7037d317
commit
9f7cdc34b4
@ -18,7 +18,6 @@ use Carbon\Carbon;
|
||||
use DB;
|
||||
use Redirect;
|
||||
use Request;
|
||||
use Response;
|
||||
|
||||
/**
|
||||
* @apiDefine dialog
|
||||
@ -1022,7 +1021,7 @@ class DialogController extends AbstractController
|
||||
}
|
||||
//
|
||||
$filePath = public_path($array['path']);
|
||||
return Response::streamDownload(function() use ($filePath) {
|
||||
return Base::streamDownload(function() use ($filePath) {
|
||||
echo file_get_contents($filePath);
|
||||
}, $array['name']);
|
||||
}
|
||||
|
||||
@ -1507,7 +1507,7 @@ class ProjectController extends AbstractController
|
||||
}
|
||||
//
|
||||
$filePath = public_path($file->getRawOriginal('path'));
|
||||
return Response::streamDownload(function() use ($filePath) {
|
||||
return Base::streamDownload(function() use ($filePath) {
|
||||
echo file_get_contents($filePath);
|
||||
}, $file->name);
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ namespace App\Models;
|
||||
|
||||
use App\Module\Base;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Response;
|
||||
|
||||
/**
|
||||
* App\Models\FileContent
|
||||
@ -97,7 +96,7 @@ class FileContent extends AbstractModel
|
||||
} else {
|
||||
$filePath = public_path($content['url']);
|
||||
}
|
||||
return Response::streamDownload(function() use ($filePath) {
|
||||
return Base::streamDownload(function() use ($filePath) {
|
||||
echo file_get_contents($filePath);
|
||||
}, $name);
|
||||
}
|
||||
@ -128,7 +127,7 @@ class FileContent extends AbstractModel
|
||||
if ($download) {
|
||||
$filePath = public_path($path);
|
||||
if (isset($filePath)) {
|
||||
return Response::streamDownload(function() use ($filePath) {
|
||||
return Base::streamDownload(function() use ($filePath) {
|
||||
echo file_get_contents($filePath);
|
||||
}, $name);
|
||||
} else {
|
||||
|
||||
@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Config;
|
||||
use Overtrue\Pinyin\Pinyin;
|
||||
use Redirect;
|
||||
use Request;
|
||||
use Response;
|
||||
use Storage;
|
||||
use Validator;
|
||||
|
||||
@ -3182,4 +3183,17 @@ class Base
|
||||
throw new ApiException($validator->errors()->first());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 流下载,解决没有后缀无法下载的问题
|
||||
* @param $callback
|
||||
* @param $name
|
||||
* @return mixed
|
||||
*/
|
||||
public static function streamDownload($callback, $name = null) {
|
||||
if ($name && !str_contains($name, '.')) {
|
||||
$name .= ".";
|
||||
}
|
||||
return Response::streamDownload($callback, $name);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user