Skip to content

Instantly share code, notes, and snippets.

@RakibSiddiquee
Created August 9, 2017 10:38
Show Gist options
  • Select an option

  • Save RakibSiddiquee/7aacc264ba59fda37fdd9c71e73601d3 to your computer and use it in GitHub Desktop.

Select an option

Save RakibSiddiquee/7aacc264ba59fda37fdd9c71e73601d3 to your computer and use it in GitHub Desktop.
Upload image with from imagebox of tinymce
1. Add following input file right after textarea field...
<input name="image" type="file" id="upload" class="hidden" onchange="">
2. Add the following code in tinymce jquery code block...
file_picker_callback: function(callback, value, meta) {
if (meta.filetype == 'image') {
$('#upload').trigger('click');
$('#upload').on('change', function() {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var imagevalue = e.target.result; // Get the target value in base64 bit
var filename = $("#upload").val().substring($("#upload").val().lastIndexOf('\\') + 1); // get the image name
// Pass the imagevalue and filename to server end and pass the image in folder
$.post('{{ url("backend/manual-photo-upload") }}', {"_token": "{{ csrf_token() }}", 'filename': filename, 'imagevalue': imagevalue}, function (data) {
var data = 'http://dev.jagonews24.com/media/imgAll/'+data; // make a var and pass it to view
//console.log(data);
callback(data, {
alt: ''
});
});
};
reader.readAsDataURL(file);
});
}
},
// Old tinymce code
file_picker_callback: function(callback, value, meta) {
if (meta.filetype == 'image') {
$('#upload').trigger('click');
$('#upload').on('change', function() {
var file = this.files[0];
console.log(file);
var reader = new FileReader();
reader.onload = function(e) {
callback(e.target.result, {
alt: ''
});
};
reader.readAsDataURL(file);
});
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment