mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-15 06:09:58 +08:00
fix showing empty file when UploadFile::error !== UPLOAD_ERR_OK
This commit is contained in:
parent
53777163d9
commit
c37091d0f1
@ -10,6 +10,7 @@ use Session;
|
||||
use App\Models\User;
|
||||
use App\Models\Texture;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Exceptions\PrettyPageException;
|
||||
use App\Services\Repositories\UserRepository;
|
||||
|
||||
@ -138,7 +139,9 @@ class SkinlibController extends Controller
|
||||
|
||||
public function handleUpload(Request $request)
|
||||
{
|
||||
$this->checkUpload($request);
|
||||
if (($response = $this->checkUpload($request)) instanceof JsonResponse) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$t = new Texture();
|
||||
$t->name = $request->input('name');
|
||||
@ -250,6 +253,12 @@ class SkinlibController extends Controller
|
||||
*/
|
||||
private function checkUpload(Request $request)
|
||||
{
|
||||
if ($file = $request->files->get('file')) {
|
||||
if ($file->getError() !== UPLOAD_ERR_OK) {
|
||||
return json(Utils::convertUploadFileError($file->getError()), $file->getError());
|
||||
}
|
||||
}
|
||||
|
||||
$this->validate($request, [
|
||||
'name' => 'required|no_special_chars',
|
||||
'file' => 'required|max:'.option('max_upload_file_size'),
|
||||
|
@ -140,4 +140,20 @@ class Utils
|
||||
return $str;
|
||||
}
|
||||
|
||||
public static function convertUploadFileError($errno = 0)
|
||||
{
|
||||
$phpFileUploadErrors = [
|
||||
0 => 'There is no error, the file uploaded with success',
|
||||
1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',
|
||||
2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
|
||||
3 => 'The uploaded file was only partially uploaded',
|
||||
4 => 'No file was uploaded',
|
||||
6 => 'Missing a temporary folder',
|
||||
7 => 'Failed to write file to disk.',
|
||||
8 => 'A PHP extension stopped the file upload.',
|
||||
];
|
||||
|
||||
return $phpFileUploadErrors[$errno];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user