title: Laravel 5.1 Uploading & Saving Base64 Image Sent From Form
body: <p>I'm using laravel as the backend of my application, the front end allows the user to enter the first name aswell as uploading a photo of themselves.. Using html5 they can crop the photo on page and the cropped photo is sent on form submit to my controller.. </p>
  
  <p><strong>I'm getting the following error:</strong></p>
  
  <pre><code>ErrorException in testcontroller.php line 31:
  Only variables should be passed by reference
  </code></pre>
  
  <p><strong>Here's my View which contains the form and the function for on page crop:</strong></p>
  
  <pre><code>&lt;form enctype="multipart/form-data" action="/testing" method="post" role="form"&gt;
     &lt;input type="hidden" name="_token" value="{{ csrf_token() }}"&gt;
     &lt;div class="form-group"&gt;
        &lt;label for="name"&gt;Name&lt;/label&gt;
           &lt;input type="text" name="name" class="form-control" /&gt;
     &lt;/div&gt;
  
     &lt;div class="form-group"&gt;
        &lt;label for="name"&gt;Title&lt;/label&gt;
          &lt;input type="text" name="title" class="form-control" /&gt;
     &lt;/div&gt;
  
  
     &lt;div class="form-group"&gt;
        &lt;label&gt;Image&lt;/label&gt;
          &lt;div class="dropzone" data-width="960" data-height="540" data-ajax="false" data-originalsave="true" style="width: 100%;"&gt;
           &lt;input type="file" name="thumb" required="required" /&gt;
          &lt;/div&gt;
     &lt;/div&gt;
  
     &lt;button type="submit" class="btn btn-default"&gt;Submit&lt;/button&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Here's my Controller which saves the photo locally and eventually update the customers record with the url to the file on my server:</strong></p>
  
  <pre><code>public function test(Request $request)
      {
          $error                    = false;
  
          $absolutedir            = dirname(__FILE__);
          $dir                    = '/tmp/';
          $serverdir              = $absolutedir.$dir;
          $filename               = array();
  
          foreach($_FILES as $name =&gt; $value) {
              $json                   = json_decode($_POST[$name.'_values']);
              $tmp                    = explode(',',$json-&gt;data);
              $imgdata                = base64_decode($tmp[1]);
  </code></pre>
  
  <p><strong>LINE 31 $extension              = strtolower(end(explode('.',$json->name)));</strong></p>
  
  <pre><code>            $fname                  = substr($json-&gt;name,0,-(strlen($extension) + 1)).'.'.substr(sha1(time()),0,6).'.'.$extension;
  
  
              $handle                 = fopen($serverdir.$fname,'w');
              fwrite($handle, $imgdata);
              fclose($handle);
  
              $filename[]             = $fname;
          }  
  
          return view('upload');
      }
  </code></pre>
  
  <p><strong>I'm getting the following error:</strong></p>
  
  <pre><code>ErrorException in testcontroller.php line 31:
  Only variables should be passed by reference
  </code></pre>
  
  <blockquote>
    <p>LINE 31 $extension              =
    strtolower(end(explode('.',$json->name)));</p>
  </blockquote>