> php教程 > php手册 > How to use Redactor image upload in laravel 4?

How to use Redactor image upload in laravel 4?

WBOY
풀어 주다: 2016-06-06 20:09:45
원래의
1007명이 탐색했습니다.

FROM?http://stackoverflow.com/questions/16736196/how-to-use-redactor-image-upload-in-laravel-4 I am trying to use Redactor with Laravel4. I can succesfully edit my textarea but I cant get to work with image uploads. When I try to upload a

FROM?http://stackoverflow.com/questions/16736196/how-to-use-redactor-image-upload-in-laravel-4

I am trying to use Redactor with Laravel4. I can succesfully edit my textarea but I cant get to work with image uploads. When I try to upload a file I get 500 error and In developer tools , I can see

Request URL:http://projemiz.dev/admin/blogs/3/postimage/3
로그인 후 복사

This is my link for redactor photo upload:

$('#editor').redactor({ imageUpload: "postimage/{{$post->id}}"});
로그인 후 복사

My routes are inside prefixes :

# Blog Management
Route::group(array('prefix' => 'blogs'), function()
{
    Route::get('/', array('as' => 'blogs', 'uses' => 'Controllers\Admin\BlogsController@getIndex'));
    Route::get('create', array('as' => 'create/blog', 'uses' => 'Controllers\Admin\BlogsController@getCreate'));
    Route::post('create', 'Controllers\Admin\BlogsController@postCreate');
    Route::get('{blogId}/edit', array('as' => 'update/blog', 'uses' => 'Controllers\Admin\BlogsController@getEdit'));
    Route::post('{blogId}/edit', 'Controllers\Admin\BlogsController@postEdit');
    Route::post('{blogId}/postimage','Controllers\Admin\BlogsController@postImage');
    Route::get('{blogId}/delete', array('as' => 'delete/blog', 'uses' => 'Controllers\Admin\BlogsController@getDelete'));
});
로그인 후 복사

and my controller is :

public function postImage($blogId) {
    $path = base_path().'/public/uploads/img/posts/' . (int)$blogId;
    $image = Input::file('photo');
    if (Input::hasFile('photo'))
    {
    $fileName = $file->getClientOriginalName();
    $image->move($path,$fileName);
        $image = new Image;
        $image->name = $fileName.name;
        $image->save();
        // resizing an uploaded file
        Image::make($image->getRealPath())->resize(300, 200)->save($path.'thumb-'.$fileName);
        Image::make($image->getRealPath())->resize(300, 200)->save($path.'thumb-'.$fileName);
        //File::delete( $path . '/' . Input::file('file.name'));*/
    }
}
로그인 후 복사

Can anyone help me to fix my link inside redactor?

Try changing your js-script this:

$('#editor').redactor({ imageUpload: "/{{$post->id}}/postimage"});
로그인 후 복사

In the upload function return the path of the image after upload

public function postImage($blogId) 
{
    $path = base_path().'/public/uploads/img/posts/' . (int)$blogId;
    $image = Input::file('photo');
    if (Input::hasFile('photo'))
    {
        $fileName = $file->getClientOriginalName();
        $image->move($path,$fileName);
        $image = new Image;
        $image->name = $fileName.name;
        $image->save();
        // resizing an uploaded file
        Image::make($image->getRealPath())->resize(300, 200)->save($path.'thumb-'.$fileName);
        Image::make($image->getRealPath())->resize(300, 200)->save($path.'thumb-'.$fileName);
        // Return Image path as JSON
       if ($file->move($path, $fileName))
       {
           return Response::json(array('filelink' => $path . '/' . $fileName));
       }
    }
}
로그인 후 복사
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿