我學習Laravel 4.2版本,我寫了一個簡單的表格,上傳與此代碼的文件工作:上傳表單不正常的路由
<form action="{{url('form')}}" method="post" enctype="multipart/form-data">
<input type="file" name="libro">
<input type="submit" value="invia">
</form>
這是我的路線:
Route::get('form',function(){
return View::make('form');
});
Route::post('dati',function(){
$file=Input::get('libro');
return $file;
});
當我參觀路線我得到這個錯誤:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException thrown with message ""
Stacktrace:
#14 Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:210
#13 Illuminate\Routing\RouteCollection:methodNotAllowed in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:197
#12 Illuminate\Routing\RouteCollection:getOtherMethodsRoute in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:145
#11 Illuminate\Routing\RouteCollection:match in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1054
#10 Illuminate\Routing\Router:findRoute in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1022
#9 Illuminate\Routing\Router:dispatchToRoute in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1001
#8 Illuminate\Routing\Router:dispatch in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:775
#7 Illuminate\Foundation\Application:dispatch in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:745
#6 Illuminate\Foundation\Application:handle in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Session/Middleware.php:72
#5 Illuminate\Session\Middleware:handle in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php:47
#4 Illuminate\Cookie\Queue:handle in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php:51
#3 Illuminate\Cookie\Guard:handle in /opt/lampp/htdocs/blog/vendor/stack/builder/src/Stack/StackedHttpKernel.php:23
#2 Stack\StackedHttpKernel:handle in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:641
#1 Illuminate\Foundation\Application:run in /opt/lampp/htdocs/blog/public/index.php:49
#0 require_once in /opt/lampp/htdocs/blog/server.php:19
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException thrown with message ""
Stacktrace:
#14 Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:210
#13 Illuminate\Routing\RouteCollection:methodNotAllowed in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:197
#12 Illuminate\Routing\RouteCollection:getOtherMethodsRoute in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:145
#11 Illuminate\Routing\RouteCollection:match in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1054
#10 Illuminate\Routing\Router:findRoute in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1022
#9 Illuminate\Routing\Router:dispatchToRoute in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1001
#8 Illuminate\Routing\Router:dispatch in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:775
#7 Illuminate\Foundation\Application:dispatch in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:745
#6 Illuminate\Foundation\Application:handle in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Session/Middleware.php:72
#5 Illuminate\Session\Middleware:handle in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php:47
#4 Illuminate\Cookie\Queue:handle in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php:51
#3 Illuminate\Cookie\Guard:handle in /opt/lampp/htdocs/blog/vendor/stack/builder/src/Stack/StackedHttpKernel.php:23
#2 Stack\StackedHttpKernel:handle in /opt/lampp/htdocs/blog/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:641
#1 Illuminate\Foundation\Application:run in /opt/lampp/htdocs/blog/public/index.php:49
#0 require_once in /opt/lampp/htdocs/blog/server.php:19
即使我重寫我的代碼,這個我有同樣的問題:
Route::get('form',function(){
return View::make('form');
});
Route::post('dati',function(){
$file=Input::File('libro');
return $file;
});
而且也因爲這樣:
Route::post('dati',function(){
$file=Input::file('libro')->getClientOriginalName();
return $file;
});
反正。我在Ubuntu 15.10上,並且正在使用PHP 5.6.11運行XAMPP燈棧。 apache2和MySQL。一切正常,但不是這樣。
我將返回response-> download($ file,$ filename,$ headers);更重要的是我會def使用控制器'$ headers = array('Content-Type:application/pd'); 返回響應::下載($文件,$文件名,$頭);' –
謝謝我解決了。我的錯誤是在路線後。感謝您的分享 –