Better to store just name in the database.
Store Image to Filesystem
I want to store image and someone come with this statement :
It's better to store the image on the filesystem and only store the image filename in the db. Don't store the image in the db. There is no good reason to do so and it slows things down and takes more memory whereas a simple link to the image on the filesystem removes all of that from the equation. Files->filesystem, Data->database.
Now the problem, how could i do it ? please guide me step by step and how to filter the file (give the protection) so if the input file extention is wrong (ex : not .jpg) the button disable and flash massage appear
Here is code for my blade form
<div align="center">
<h5><b>Tanda Tangan</b></h5>
<h7>(Tanda Tangan Berupa Gambar)</h7><p></p>
</div>
<div align="center">
<div>
<h7><b>Pemohon (Customers)</b></h7>
<h7>                            </h7>
<h7><b>Disetujui Oleh (Customers)</b></h7>
</div>
<div>
<input class="field" name="ttdcus1" type="file">
<input class="field" name="ttdcus1" type="file">
<br>
<br>
<br>
<br><br>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4" align="center">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-sign-in"></i> Lanjut
</button>
</div>
</div>
On my controller
if($request->hasFile('ttdcus1')) {
$imageTempName = $request->file('ttdcus1')->getPathname();
$imageName = $request->file('ttdcus1')->getClientOriginalName();
$path = base_path() . '/public/img/ttd';
$request->file('ttdcus1')->move($path , $imageName);
}
$keluhan = keluhan::create($request->all());
$keluhan->ttd_pemohon = $imageName;
$keluhan->save();
Solved. Thank You Guys for all information.
Please or to participate in this conversation.