title: decode and move base64 encoded image in laravel
body: <p>I am trying to implement a image upload with other form elements with dropzone.js in laravel. So far I've managed to display the drag and drop image upload view with other form elements. And also get POST details from the submitted form. But when dropzone is passing the uploaded image to the database data save function it encode image with base64. I think I've managed to get the file extension also. And when I submit the button it gives me this error <strong>"Call to a member function move() on string"</strong> . Please put me in the right direction. </p>
  
  <p>Here is the Form</p>
  
  <pre><code>&lt;form class="form-horizontal" action="{{ route('save-slider-content') }}" method="POST" enctype="multipart/form-data"&gt;
     {{ csrf_field() }}
     &lt;div class="box-body"&gt;
       &lt;div class="form-group"&gt;
         &lt;label for="inputEmail3" class="col-sm-2 control-label"&gt;Title&lt;/label&gt;
         &lt;div class="col-sm-10"&gt;
           &lt;input type="text" class="form-control" name="sliderTitle" id="sliderTitle" placeholder="Title of the post goes here"&gt;
         &lt;/div&gt;
       &lt;/div&gt;
       &lt;input type="hidden" name="date" id="date" value="&lt;?php echo date("d-m-Y"); ?&gt;"&gt;
       &lt;div class="form-group"&gt;
         &lt;label for="image" class="col-sm-2 control-label"&gt;Image&lt;/label&gt;
         &lt;input hidden id="file" name="file"/&gt;
         &lt;div class="col-sm-10"&gt;
           &lt;div class="dropzone needsclick dz-clickable" id="fileUpload"&gt;
             &lt;div class="dz-default dz-message"&gt;
                &lt;i class="fa fa-image fa-5x"&gt;&lt;/i&gt;
                &lt;h3 class="sbold"&gt;Drop an image here to upload&lt;/h3&gt;
                &lt;span&gt;You can also click to open file browser&lt;/span&gt;
            &lt;/div&gt;
           &lt;/div&gt;
         &lt;/div&gt;
       &lt;/div&gt;
       &lt;div class="form-group"&gt;
         &lt;label for="inputEmail3" class="col-sm-2 control-label"&gt;Link&lt;/label&gt;
         &lt;div class="col-sm-10"&gt;
           &lt;input type="text" class="form-control" name="sliderLink" id="sliderLink" placeholder="Provide a link"&gt;
         &lt;/div&gt;
       &lt;/div&gt;
     &lt;/div&gt;&lt;br&gt;
     &lt;!-- /.box-body --&gt;
     &lt;div class="box-footer"&gt;
       &lt;button type="submit" class="btn btn-default"&gt;Cancel&lt;/button&gt;
       &lt;button type="submit" class="btn btn-info pull-right"&gt;Post&lt;/button&gt;
     &lt;/div&gt;
     &lt;!-- /.box-footer --&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>Here is the dropzone configuration</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  Dropzone.options.fileUpload = {
    url: "save-slider-content",
    addRemoveLinks: true,
    accept: function(file) {
        let fileReader = new FileReader();
  
        fileReader.readAsDataURL(file);
        fileReader.onloadend = function() {
  
            let content = fileReader.result;
            $('#file').val(content);
            file.previewElement.classList.add("dz-success");
        }
        file.previewElement.classList.add("dz-complete");
    }
  }
    &lt;/script&gt;
  </code></pre>
  
  <p>Route</p>
  
  <pre><code>Route::post('store-slider-content', [ 'as' =&gt; 'save-slider-content', 'uses' =&gt; 'SliderContent@save_slider_data']);
  </code></pre>
  
  <p>save_slider_data function in Controller</p>
  
  <pre><code>public function save_slider_data(Request $request)
  {
    $slider = new Slider;
    $slider-&gt;title = $request-&gt;sliderTitle;
    $slider-&gt;title_sin = $request-&gt;sliderTitleSin;
    $slider-&gt;date = $request-&gt;date;
    $slider-&gt;link = $request-&gt;sliderLink;
  
    $file = $request-&gt;file;;
    $image_data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $file));
    $f = finfo_open();
    $mime_type = finfo_buffer($f, $image_data, FILEINFO_MIME_TYPE);
    $imageName = time().'.'.$mime_type;
    $image_data-&gt;move(public_path('slider_uploads'), $imageName);
    return response()-&gt;json(['success'=&gt;$imageName]);
  
    $slider-&gt;img_url = $imageName;
  
    $slider-&gt;save();
  }
  </code></pre>