2
我想通過表格上傳照片。我有照片資源正確設置。帶有以下內容的表格照片:標識,標題,標題,路徑:字符串。Laravel4:上傳圖片
這是要求用戶上傳的圖片形式的一部分:
{{Form::open(array('route' => 'CrewRegisterPost', 'role'=>'form','files'=> true,'class' => 'form-horizontal','style' => 'margin-top:15px;'))}}
<label class="col-md-4 control-label" for="license_image">Colour scanned copy of Licence *</label>
<div class="col-md-6">
<input type="file" name="license_image" accept="image/*" required>
{{Form::showError('license_image')}}
</div>
{{Form::close()}}
這是一個簡單的存儲方法我發到現在爲止:
public function createNewCrew($data){
$user = $this->storeNewUserCommonFields($data,User::getTypeNumberFor('Crew'));
$validator = new Saarang\Validators\FlightCrewValidator($data);
if($validator->fails()){
$this->messageBag->merge($validator->errors->getMessages());
}
if($user){
$Crew = new Crew();
$Crew->user_id = $user->getKey();
$Crewlicense_image = $data['license_image'];
$savepath = 'public/img/';
$filename = time() . '-' .$Crewlicense_image;
Input::file('license_image')->move($savepath, $filename);
$Crew->save();
return $user;
}
}
But when I run it I get the following error: Call to a member function move() on a non-object
我怎麼可以把正確的那裏執行檢索文件並存儲在公共/ img文件夾?
首先,您應該製作一個表單並將enctype屬性設置爲多部分表單數據,然後將您的輸入置於上述表單中。 – user3786134
就像一個建議,dropzone插件幫助了我很多。 –