Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function ajaxImage()
- {
- $file = Input::file('image');
- $destinationPath = public_path();
- $filename = $file->getClientOriginalName();
- if(Input::file('image')->move($destinationPath, $filename)) {
- echo $destinationPath.$filename;
- }
- }
- $(document).ready(function(){
- $('#description').summernote({
- height: 300,
- onImageUpload: function(files, editor, welEditable) {
- sendFile(files[0], editor, welEditable);
- }
- });
- function sendFile(file, editor, welEditable) {
- var data = new FormData();
- data.append("file", file);
- var url = '/articles/ajaximage';
- $.ajax({
- data: data,
- type: "POST",
- url: url,
- cache: false,
- contentType: false,
- processData: false,
- success: function(url) {
- alert('Success');
- editor.insertImage(welEditable, url);
- }
- });
- }
- });
- <meta name="csrf-token" content="{{ csrf_token() }}" />
- $.ajaxSetup({
- headers: {
- 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
- }
- });
- Route::post('ajaximage', function(){
- $file = Request::file('file');
- $destinationPath = public_path().'/uploads/';
- $filename = $file->getClientOriginalName();
- $file->move($destinationPath, $filename);
- echo url().'/uploads/'.$filename;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement