Image Intervention changing file upload to multiple files
I am using Intervention to upload files. Now I want to have the files upload as an array of files.(multiple) How do I go about it? I tried lab_quote[] but is not working. Or is it best practice to have each file as a separate column in the db?
if ($request->hasFile('lab_quote')){
// get file Name
$quotenameWithExt = $request->file('lab_quote')->getClientOriginalName();
//The image path and name
$quotefilename = pathinfo($quotenameWithExt, PATHINFO_FILENAME);
// get the exxtension
$quoteextension = $request->file('lab_quote')->getClientOriginalExtension();
// Name append a time stamp
$labquotefileNameToStore = $quotefilename.'_' .time(). '.' . $quoteextension;
// Move the file to the folder
// $stlpath = $request->file('stl_image')->storeAs('public/uploads', $stlfileNameToStore);
$qtlpath = $request->file('lab_quote')->storeAs('public/uploads/thumbnails', $labquotefileNameToStore);
// Resize
$quote = public_path('storage/uploads/thumbnails'. $labquotefileNameToStore);
$qto = Image::make($_FILES['lab_quote']['tmp_name']);
$qto->resize('443','313');
$qto->save($quote);
}
Exactly the same code you have, but in a foreach loop. And you may need to create a new table specifically for files, because now you save more than one.
foreach($request->get('files') as $file) {
// rename
// prepare file
// resize
// store it
}
@AP3TWE - no, you can't use $table->string('lab_quote[]')->nullable(); - if you want to add more images to a Model, then you have to create another table and create relationship (one to many) between the tables. Another option is to store name of the files in a comma separate string format, something like this: fileName1, fileName2, fileName3