Advertisement
rodro1

Summernote file upload

Jul 25th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. // app-admin.js
  2.  
  3. $(document).ready(function() {
  4. $('.summernote').summernote({
  5. height: 400,
  6. callbacks: {
  7. onImageUpload: function(files, editor, welEditable) {
  8. // upload image to server and create imgNode...
  9. var that = $(this);
  10. sendFile(files[0], editor, welEditable, that);
  11. }
  12. }
  13. });
  14.  
  15. function sendFile(file, editor, welEditable, that) {
  16. data = new FormData();
  17. data.append("file", file);
  18. $.ajax({
  19. data: data,
  20. type: "POST",
  21. url: base_url + "/admin/upload_summernote_photo",
  22. cache: false,
  23. contentType: false,
  24. processData: false,
  25. success: function(url) {
  26. $(that).summernote('insertImage', url)
  27. }
  28. });
  29. }
  30.  
  31.  
  32. //adminsettingcontroller
  33.  
  34. public function upload_summernote_photo(){
  35. if ($_FILES['file']['name']) {
  36. if (!$_FILES['file']['error']) {
  37. $name = md5(rand(100, 200));
  38. $ext = explode('.', $_FILES['file']['name']);
  39. $filename = $name . '.' . $ext[1];
  40.  
  41.  
  42. $destination = public_path('uploads/images/') . $filename;//change this directory
  43. $location = $_FILES["file"]["tmp_name"];
  44. move_uploaded_file($location, $destination);
  45. echo url('/') . '/uploads/images/' . $filename;//change this URL
  46. }
  47. else
  48. {
  49. echo $message = 'Ooops! Your upload triggered the following error: '.$_FILES['file']['error'];
  50. }
  51. }
  52. }
  53.  
  54. // verify csrf_token
  55. // except
  56.  
  57. '/admin/upload_summernote_photo'
  58.  
  59. // add on admin group route
  60.  
  61. Route::post('/upload_summernote_photo', 'AdminSettingController@upload_summernote_photo');
  62.  
  63. // add folder images
  64. uploads/images
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement