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

How to use Redactor image upload in laravel 4?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:09:45
Original
1057 people have browsed it

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
Copy after login

This is my link for redactor photo upload:

$('#editor').redactor({ imageUpload: "postimage/{{$post->id}}"});
Copy after login

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'));
});
Copy after login

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'));*/
    }
}
Copy after login

Can anyone help me to fix my link inside redactor?

Try changing your js-script this:

$('#editor').redactor({ imageUpload: "/{{$post->id}}/postimage"});
Copy after login

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));
       }
    }
}
Copy after login
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
How to learn php well
From 1970-01-01 08:00:00
0
0
0
How to write a loop?
From 1970-01-01 08:00:00
0
0
0
How to run/debug your PHP code?
From 1970-01-01 08:00:00
0
0
0
How to save online editor
From 1970-01-01 08:00:00
0
0
0
How to sign up?
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template