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