Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Summernote image upload and save on server instead of base64 data saving on Database.
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);
}
});
}
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;
}
@maximusmcc

This comment has been minimized.

Copy link

@maximusmcc maximusmcc commented Apr 26, 2018

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 :-)

@Mcinfas153

This comment has been minimized.

Copy link

@Mcinfas153 Mcinfas153 commented Sep 28, 2018

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