Search code examples
phplaravel-5redactor

Redactor image upload not working on laravel 5


Same code working in laravel 4 but not working in laravel 5.

Here is all codes :

//Redactor Image Upload
Route::post('image/upload', function(){
    $image = Input::file('file');
    $filename = 'bdtimes'.rand(10, 99999999).'.'.$image->getClientOriginalExtension();
    $move = Image::make($image->getRealPath())->save('uploads/images/original/'.$filename);

    if($move){
        return Response::json(['filelink'=>'/uploads/images/original/'. $filename]);
    }else{
        return Response::json(['error'=>true]);
    }
});

Redactor Script :

$(function()
{
    $('#redactor').redactor({
            focus: true,
            imageUpload: '{{ url() }}/image/upload',
            imageManagerJson: '{{ url() }}/image.php',
            plugins: ['table', 'video','imagemanager','fontcolor','fontsize','fullscreen'],
            maxHeight: 300,
            minHeight: 300
        });
});

In Chrome Developer Tool this error showing when i try to upload image.

Failed to load resource: the server responded with a status of 500 (Internal Server Error)        http://localhost:8000/image/upload

What is problem ? Please help me .

Thanks


Solution

  • Updated Answer

    There is a problem with the token. Change the Redactor script..

    $(function()
    {
        $('#redactor').redactor({
            focus: true,
            imageUpload: '{{ url() }}/image/upload?_token=' + '{{ csrf_token() }}',
            imageManagerJson: '{{ url() }}/image.php',
            plugins: ['table', 'video','imagemanager','fontcolor','fontsize','fullscreen'],
            maxHeight: 300,
            minHeight: 300
        });
    });