1

I got error while uploading multiple image in laravel.

HTML Code :-

<div class="form-group">
<label for="title">Art Gallery</label>
 <input type="file" name="art_image[]" id="art_image" value="{{old('art_image') }}"  accept="image/*"  multiple="multiple">
</div>

:- Controller code

if ($request->hasFile('art_image')) {
   $fileImage1 = $request->file('art_image');
   $StoreName = array();
   foreach ($fileImage1 as $files) {
         $filename1 = time().rand(1,100).".".$files->getClientOriginalExtension();
     $StoreName[] = $filename1;
     if($files->move(ART_IMAGE_DIR_PATH, $filename))
         {
              $data['art_image'] = $filename1;
           }
        }
   $artdetail_model->art_image = serialize($StoreName);
     }

I got below error

preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

3
  • Why don't you make a copypaste from your code, instead of REWRITING it? There is a uninitialized $filename variable that I guess in your original code is $filename1 Commented Jun 1, 2016 at 9:30
  • Where is that preg_replace called from? What is the error stack? Commented Jun 1, 2016 at 9:38
  • ErrorException in helpers.php line 671: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in helpers.php line 671 at HandleExceptions->handleError('2', 'preg_replace(): Parameter mismatch, pattern is a string while replacement is an array', '/var/www/html/MuseumManagement1/vendor/laravel/framework/src/Illuminate/Support/helpers.php', '671', array('search' => '\?', 'replace' => array(null, array(null), '11'), 'subject' => 'update art_detail set art_cover_image = , art_image = ? where id = ?', 'value' => array(null))) Commented Jun 1, 2016 at 10:00

1 Answer 1

0

Problem is when you are submitting multiple images it becomes an array of pictures instead of a single string. So it is trying to save an array to the database instead of a string which it is expecting. If you make it so your photo variable is a json_encoded array of pictures then you should be able to save them.

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

i am store serialize image array in database.what is the solution to remove this error?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.