Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // app-admin.js
- $(document).ready(function() {
- $('.summernote').summernote({
- height: 400,
- callbacks: {
- onImageUpload: function(files, editor, welEditable) {
- // upload image to server and create imgNode...
- var that = $(this);
- sendFile(files[0], editor, welEditable, that);
- }
- }
- });
- function sendFile(file, editor, welEditable, that) {
- data = new FormData();
- data.append("file", file);
- $.ajax({
- data: data,
- type: "POST",
- url: base_url + "/admin/upload_summernote_photo",
- cache: false,
- contentType: false,
- processData: false,
- success: function(url) {
- $(that).summernote('insertImage', url)
- }
- });
- }
- //adminsettingcontroller
- public function upload_summernote_photo(){
- if ($_FILES['file']['name']) {
- if (!$_FILES['file']['error']) {
- $name = md5(rand(100, 200));
- $ext = explode('.', $_FILES['file']['name']);
- $filename = $name . '.' . $ext[1];
- $destination = public_path('uploads/images/') . $filename;//change this directory
- $location = $_FILES["file"]["tmp_name"];
- move_uploaded_file($location, $destination);
- echo url('/') . '/uploads/images/' . $filename;//change this URL
- }
- else
- {
- echo $message = 'Ooops! Your upload triggered the following error: '.$_FILES['file']['error'];
- }
- }
- }
- // verify csrf_token
- // except
- '/admin/upload_summernote_photo'
- // add on admin group route
- Route::post('/upload_summernote_photo', 'AdminSettingController@upload_summernote_photo');
- // add folder images
- uploads/images
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement