Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant upload images by send to server buton. #54

Open
JSanGall opened this issue Dec 11, 2020 · 1 comment
Open

Cant upload images by send to server buton. #54

JSanGall opened this issue Dec 11, 2020 · 1 comment

Comments

@JSanGall
Copy link

JSanGall commented Dec 11, 2020

Im trying to install correctly but the send to server buton dont work. I get 419 error.

https://www.imagenes-temporales.com/subidas/ver/73gor8/

In spite of, I can upload images to filemanager directly at the filemaneger url, and later I can load it to the CKEditor through the image information button.

I have:
<meta name="csrf-token" content="{{ csrf_token() }}">

And I have:

<script>
  var options = {
    filebrowserImageBrowseUrl: '{{ asset("/laravel-filemanager?type=Images") }}',
		filebrowserImageUploadUrl: '{{ asset("/laravel-filemanager/upload?type=Images&_token=") }}',
		filebrowserBrowseUrl: '{{ asset("/laravel-filemanager?type=Files") }}',
		filebrowserUploadUrl: '{{ asset("/laravel-filemanager/upload?type=Files&_token=") }}',
	width: 'auto',
    height: 550,
    extraAllowedContent: 'h1;a[!href]' 
  };	
</script>
<script>
CKEDITOR.replace('body', options);
</script>

What is the problem?

@HashmatWaziri
Copy link

Blade

<script src="//cdn.ckeditor.com/4.15.0/full/ckeditor.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.6.2/adapters/jquery.js"></script>
   <script>
    $('textarea[name=offerLetter]').ckeditor({
        height: 200,
        filebrowserUploadUrl: "{{route('ckeditor.upload', ['_token' => csrf_token() ])}}",
        filebrowserUploadMethod: 'form'
     });
   </script>

Route:

Route::post('images/upload', 'ImageController@upload')->name('ckeditor.upload');

Create ImageController, then put this method inside it:

public function upload(Request $request)
{
    if($request->hasFile('upload')) {
        $originName = $request->file('upload')->getClientOriginalName();
        $fileName = pathinfo($originName, PATHINFO_FILENAME);
        $extension = $request->file('upload')->getClientOriginalExtension();
        $fileName = $fileName.'_'.time().'.'.$extension;

        $request->file('upload')->move(public_path('images'), $fileName);

        $CKEditorFuncNum = $request->input('CKEditorFuncNum');
        $url = asset('images/'.$fileName);
        $msg = 'Image uploaded successfully';
        $response = "<script>window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum, '$url', '$msg')</script>";

        @header('Content-type: text/html; charset=utf-8');
        echo $response;
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants