Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. public function ajaxImage()
  2. {
  3. $file = Input::file('image');
  4. $destinationPath = public_path();
  5. $filename = $file->getClientOriginalName();
  6. if(Input::file('image')->move($destinationPath, $filename)) {
  7. echo $destinationPath.$filename;
  8. }
  9. }
  10.  
  11. $(document).ready(function(){
  12. $('#description').summernote({
  13. height: 300,
  14.  
  15. onImageUpload: function(files, editor, welEditable) {
  16. sendFile(files[0], editor, welEditable);
  17. }
  18. });
  19. function sendFile(file, editor, welEditable) {
  20. var data = new FormData();
  21. data.append("file", file);
  22. var url = '/articles/ajaximage';
  23. $.ajax({
  24. data: data,
  25. type: "POST",
  26. url: url,
  27. cache: false,
  28. contentType: false,
  29. processData: false,
  30. success: function(url) {
  31. alert('Success');
  32. editor.insertImage(welEditable, url);
  33. }
  34. });
  35. }
  36. });
  37.  
  38. <meta name="csrf-token" content="{{ csrf_token() }}" />
  39.  
  40. $.ajaxSetup({
  41. headers: {
  42. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  43. }
  44. });
  45.  
  46. Route::post('ajaximage', function(){
  47.  
  48. $file = Request::file('file');
  49. $destinationPath = public_path().'/uploads/';
  50. $filename = $file->getClientOriginalName();
  51. $file->move($destinationPath, $filename);
  52. echo url().'/uploads/'.$filename;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement