i want to make multiple upload but i dont know how. i have try to make my code but its not work.
this is my view :
<form method='post' action='' enctype="multipart/form-data">
<input type="hidden" name="_token" value="">
<div class="box-body">
<div class="box-body">
<div class='form-group col-sm-12'>
<label>Name</label>
<input type='text' class='form-control' name='id_log_patrols' required/>
</div>
<div class='form-group col-sm-4'>
<label>gambar</label>
<input type='file' class='form-control' name='photo1' required/>
</div>
<div class='form-group col-sm-4'>
<label>gambar</label>
<input type='file' class='form-control' name='photo2' required/>
</div>
<div class='form-group col-sm-4'>
<label>gambar</label>
<input type='file' class='form-control' name='photo3' required/>
</div>
<div class='form-group col-sm-12'>
<label>Name</label>
<input type='text' class='form-control' name='description' required/>
</div>
<div class='form-group col-sm-12'>
<button type='submit' class='btn btn-primary'><i class='fa fa-save'></i> Simpan</button>
</div>
</div><!-- /.box -->
</form>
and this my controller :
public function postAddSave() {
$simpan= array();
$simpan['id_log_patrols']=Request::input('id_log_patrols');
if (Request::hasfile('photo1')) {
$destinationPath = 'uploads'; // upload path
$extension = Request::file('photo1')->getClientOriginalExtension(); // getting image extension
$fileName = rand(11111,99999).'.'.$extension; // renameing image
Request::file('photo1')->move($destinationPath, $fileName); // uploading file to given path
// sending back with message
}
$simpan['photo1']=$fileName;
if (Request::hasfile('photo2')) {
$destinationPath1 = 'uploads'; // upload path
$extension1 = Request::file('photo2')->getClientOriginalExtension(); // getting image extension
$fileName1 = rand(11111,99999).'.'.$extension1; // renameing image
Request::file('photo2')->move($destinationPath1, $fileName1); // uploading file to given path
}
// sending back with message
$simpan['photo2']=$fileName1;
if (Request::hasfile('photo3')) {
$destinationPath2 = 'uploads'; // upload path
$extension2 = Request::file('photo3')->getClientOriginalExtension(); // getting image extension
$fileName2 = rand(11111,99999).'.'.$extension1; // renameing image
Request::file('photo3')->move($destinationPath2, $fileName2); // uploading file to given path
// sending back with message
$simpan['photo3']=$fileName2;
$simpan['description']=Request::input('description');
}
DB::table('log_patrol_details')->insert($simpan);
Session::flash('success', 'Data berhasil di ditambahkan');
return Redirect::to('log_details');
}
public function getEdit($id) {
$data['row'] = log_patrol_details::find($id);
return view('details_form',$data);
}
can anyone tell me what the true script for make multiple upload ?
via Chebli Mohamed
1 commentaire:
You can follow this guide on Laravel file upload to add multiple upload functionality. You have to add this to your view file
action="/multiuploads" method="post" enctype="multipart/form-data
Enregistrer un commentaire