Created
September 29, 2016 12:21
-
-
Save tojibon/118b4c80f328ca394c751d218f330a19 to your computer and use it in GitHub Desktop.
Summernote image upload and save on server instead of base64 data saving on Database.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Application.prototype.initSummerNoteJS = function() { | |
var $this = this; | |
$('#description').summernote({ | |
height: 300, //set editable area's height | |
onImageUpload: function(files, editor, $editable) { | |
$this.sendFile(files[0],editor,$editable); | |
} | |
}); | |
} | |
Application.prototype.sendFile = function(file, editor, welEditable) { | |
data = new FormData(); | |
data.append("file", file); | |
$.ajax({ | |
url: baseURL + 'home/uploader', | |
data: data, | |
cache: false, | |
contentType: false, | |
processData: false, | |
type: 'POST', | |
success: function(data){ | |
console.log(data); | |
$('#description').summernote("editor.insertImage", data, 'filename'); | |
}, | |
error: function(jqXHR, textStatus, errorThrown) { | |
console.log(textStatus+" "+errorThrown); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function uploader() { | |
$allowed = array( 'png', 'jpg', 'gif','zip' ); | |
if( isset($_FILES['file']) && $_FILES['file']['error'] == 0 ) { | |
$extension = pathinfo( $_FILES['file']['name'], PATHINFO_EXTENSION ); | |
if( !in_array( strtolower( $extension ), $allowed ) ) { | |
echo '{"status":"error"}'; | |
exit; | |
} | |
if( move_uploaded_file( $_FILES['file']['tmp_name'], WWW_ROOT . 'upload/images/'.$_FILES['file']['name'] ) ) { | |
echo Router::url('/upload/images/'.$_FILES['file']['name']); | |
exit; | |
} | |
} | |
echo '{"status":"error"}'; | |
exit; | |
} |
This was good. I Improvised it a little. I also created a complete tutorial with code and video instructions here https://a1websitepro.com/store-image-uploads-on-server-with-summernote-not-base-64/ I hope this helps someone :-)
Woooow. nice work buddy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was good. I Improvised it a little. I also created a complete tutorial with code and video instructions here https://a1websitepro.com/store-image-uploads-on-server-with-summernote-not-base-64/ I hope this helps someone :-)