I am trying to upload an image with ajax and i am getting: Failed to load resource: the server responded with a status of 500 (Internal Server Error). Here is my ajax:
$('document').ready(function() {
$('#uploadImage').change(function(){
image = $('#uploadImage').val;
token = $('#token').val();
$.ajax ({
type: 'POST',
url: '/photo',
data: { image , token },
success: function(){
$('.img-thumbnail').attr("src", 'images/new_image.png');
}
})
})
});
Here is my route: Route::post('/photo', 'ShopsController@uploadPhoto');
This is my controller:
public function uploadPhoto(Request $request)
{
//Sets file name according to authenticated shop id
$imageName = 'new_image.png';
//Save file to public/images
$img = Image::make($request->file('image'));
$img->resize(380, 300)->save('images/' . $imageName, 60);
}
And this is my form:
<form action="{{ action('ShopsController@store') }}" method="post" enctype="multipart/form-data">
<input id="token" type="hidden" name="_token" value="{{ csrf_token() }}">
<input id="uploadImage" class="btn btn-upload" type="file" name="image"> </form>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire