在我的本地环境中,我为什么要这样做,所以行得通。
if( $request->file ){
$path = $request->file('file')->store('public/chat/files');
$mime_type = $request->file('file')->getMimeType();
if( strstr( $mime_type, 'video' ) ){
$data['message_type'] = 'video';
}else if( strstr( $mime_type, 'image' ) ){
$data['message_type'] = 'image';
}else if( strstr( $mime_type, 'audio' ) ){
$data['message_type'] = 'audio';
}
但是当我在运行相同代码的数字海洋小滴上运行的apache时,出现以下错误。
[2019-02-26 11:45:48] local.ERROR: The file "" does not exist {"userId":3,"email":"user@user.com","exception":"[object] (Symfony\\Component\\HttpFoundation\\File\\Exception\\FileNotFoundException(code: 0):
The file \"\" does not exist a$
[stacktrace]
#0 /var/www/html/plugin_love_api/vendor/symfony/http-foundation/File/File.php(79): Symfony\\Component\\HttpFoundation\\File\\MimeType\\MimeTypeGuesser->guess('')
#1 /var/www/html/plugin_love_api/vendor/symfony/http-foundation/File/File.php(58): Symfony\\Component\\HttpFoundation\\File\\File->getMimeType()
#2 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Http/FileHelpers.php(60): Symfony\\Component\\HttpFoundation\\File\\File->guessExtension()
#3 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Http/UploadedFile.php(35): Illuminate\\Http\\UploadedFile->hashName()
#4 /var/www/html/plugin_love_api/app/Http/Controllers/ChatController.php(71): Illuminate\\Http\\UploadedFile->store('public/chat/fil...')
#5 [internal function]: App\\Http\\Controllers\\ChatController->sendMessage(Object(Illuminate\\Http\\Request))
#6 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
#7 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('sendMessage', Array)
#8 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\ChatController), 'se$
#9 /var/www/html/plugin_love_api/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\\Routing\\Route->runController()
#10
PHP版本为:PHP 7.2.15-0ubuntu0.18.04.1(cli)(内置:2019年2月8日14:54:22)(NTS)
我还为storage
文件夹及其所有后代设置了 777 权限。
这似乎是我正在上传的文件大小的问题。
它不能使用超过2MB的空间,但可以使用〜6kb的文件。