2016-09-15 72 views
-1

Laravel 4.2laravel 4.2文件上傳問題

我的代碼 -

圖像upload.blade.php

<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Image Upload</title> 
</head> 
<body> 
    <h1>Upload Files here</h1> 

    <form enctype="multipart/form-data" method="post" action="{{ @url('image-handle') }}"> 
    <input type="file" name="image" id="avatarImage" /> 
    <input type='hidden' name='_token' value='{{ @csrf_token() }}' /> 
    <input type="submit" name="submit"> 
</body> 
</html> 

路線 -

Route::get('image-upload', function() 
{ 
    return View::make('image-upload'); 
}); 

Route::get('image-handle', function() 
{ 
    return Input:: file('image') -> getFileName(); 
}); 

所有我想要做的是var_dump該文件提交後,但不幸的是我得到的是「哎呀,看起來像出了什麼問題」。

檢查錯誤的圖像: Error

如何解決這個問題,並在laravel 4.2成功上傳圖片?

在此先感謝!

回答

1

您在圖像處理路線上使用get動詞,並且您的表單是type = post 使它們匹配。

Route::post('image-handle', function() 
{ 
    return Input:: file('image') -> getFileName(); 
}); 
+0

你可以添加糾正碼嗎? –

0

將您的路由更改爲POST請求,您正在使用表單POST方法,您可以更改您的代碼。

{{ Form::open(array('url' => route('upload') 'image-handle', 'files' => true)) }} 

    <p> 
     {{ Form::label('image', 'Upload File') }} 
     {{ Form::file('image') }} 
    </p> 

    <p> 
     {{ Form::submit('Submit') }} 
    </p> 
{{ Form::close() }} 




Route::post('image-handle',[ 
      'as' => 'upload', 
      'uses'=>'[email protected]' 
     ]); 


//UploadController 


public function uploadFile() 
{ 

    if (Input::hasFile('image')) 
    { 
     $file = Input::file('image'); 
     $file->move('uploads', $file->getClientOriginalName()); 
    } 


} 
+0

沒有解釋的代碼是不滿意的。 – Devon

+0

你能解釋一下這個問題嗎? –

+0

路由中提到的請求是get和form有一個post方法,所以在路由中它應該是post verb – Parithiban