Suvin94
Suvin94

Reputation: 240

Image and PDF file upload - Laravel

Is there any way to upload both Image and Pdf file on the same time (Multiple) in Laravel?

I can only upload Images but im looking for a way to upload Pdf file which means it can be mix of Image and files.

   'carEvidence' => 'image|mimes:png,jpg,jpeg,doc,pdf,docx,zip|max:10000'

 if ($files = $request->file('carEvidence')) {
            $destinationPath = 'public/image/'; // upload path
            $profileImage = date('YmdHis') . "." . $files->getClientOriginalExtension();
            $files->move($destinationPath, $profileImage);
            $post['carEvidence'] = "$profileImage";
        }

Upvotes: 0

Views: 4119

Answers (2)

Suvin94
Suvin94

Reputation: 240

Solved the issue!

 'carEvidence' =>  'required|mimes:jpeg,png,jpg,zip,pdf|max:2048',

Upvotes: 2

Jovs
Jovs

Reputation: 892

Just add multiple on your input file

Example:

<input type='file' name='filename' multiple/>

Then you can click many files in one folder and in your controller you need to use foreach method to get the value

example

if($request->hasFile('filename')
{
  foreach($request->filename as $filename)
  {
    //your saving code
  }
]

Just change the name of the input.

Hope it helps!

Upvotes: 1

Related Questions