multiple file upload validation
I want a certain field (nomefile) to accept only a certain kind of file, for istance jpg and png. (It's a multiple file upload field). I copyed the BREAD controller from the Voyager framework and pasted it in app\http\controllers. Now I' trying to edit the validateBread method like this:
$rules = [
'sottotitolo' => 'required',
'nomefile.*' => 'mimes:jpg,png'
];
$messages = [
'sottotitolo.required' => 'cosa fai?'
];
but.... it doesn't work.
I am currently working in a form.
I have some issue with multiple file upload validation. I have only one field in a form which allows multiple file upload.
And this is my validation,$this->validate($request, [ 'file' =>'required', 'file.*' => 'required|mimes:pdf,jpeg,png |max:4096', ], $messages = [ 'mimes' => 'Only PDF, JPEG, PNG are allowed.' ] ); Tutuapp 9Apps ShowBox
I've done it like this:
<?php
namespace App\Http\Controllers;
use App\Item;
use App\ItemDetail;
use Illuminate\Http\Request;
class UploadController extends Controller
{
public function uploadForm()
{
return view('upload_form');
}
public function uploadSubmit(Request $request)
{
$this->validate($request, [
'name' => 'required',
'photos'=>'required',
]);
if($request->hasFile('photos'))
{
$allowedfileExtension=['pdf','jpg','png','docx'];
$files = $request->file('photos');
foreach($files as $file){
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$check=in_array($extension,$allowedfileExtension);
//dd($check);
if($check)
{
$items= Item::create($request->all());
foreach ($request->photos as $photo) {
$filename = $photo->store('photos');
ItemDetail::create([
'item_id' => $items->id,
'filename' => $filename
]);
}
echo "Upload Successfully";
}
else
{
echo '<div class="alert alert-warning"><strong>Warning!</strong> Sorry Only Upload png , jpg , doc</div>';
}
}
}
}
}?>
You can see complete example here: https://www.cloudways.com/blog/laravel-multiple-files-images-upload