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..
I'm getting the following error:
ErrorException in testcontroller.php line 31:
Only variables should be passed by reference
Here's my View which contains the form and the function for on page crop:
<form enctype="multipart/form-data" action="/testing" method="post" role="form">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" />
</div>
<div class="form-group">
<label for="name">Title</label>
<input type="text" name="title" class="form-control" />
</div>
<div class="form-group">
<label>Image</label>
<div class="dropzone" data-width="960" data-height="540" data-ajax="false" data-originalsave="true" style="width: 100%;">
<input type="file" name="thumb" required="required" />
</div>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Here's my Controller which saves the photo locally and eventually update the customers record with the url to the file on my server:
public function test(Request $request)
{
$error = false;
$absolutedir = dirname(__FILE__);
$dir = '/tmp/';
$serverdir = $absolutedir.$dir;
$filename = array();
foreach($_FILES as $name => $value) {
$json = json_decode($_POST[$name.'_values']);
$tmp = explode(',',$json->data);
$imgdata = base64_decode($tmp[1]);
LINE 31 $extension = strtolower(end(explode('.',$json->name)));
$fname = substr($json->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');
}
I'm getting the following error:
ErrorException in testcontroller.php line 31:
Only variables should be passed by reference
LINE 31 $extension = strtolower(end(explode('.',$json->name)));
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire