Skip to content

Instantly share code, notes, and snippets.

@tojibon
Created September 29, 2016 12:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tojibon/118b4c80f328ca394c751d218f330a19 to your computer and use it in GitHub Desktop.
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.
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
Copy link

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
Copy link

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