Can anyone explain with examples for everyone how to integrate CKEditor and external file browser? Where to put this code:
CKEDITOR.replace( 'editor1', {
filebrowserBrowseUrl: '/browser/browse.php',
filebrowserUploadUrl: '/uploader/upload.php'
});
And what shoud return these:
browse.php
upload.php
I think the answer for this question should be here. So many peeople asked this question, but there is no definitive guide to this plugin. SO members, maybe some of you can?
filebrowserBrowseUrl will be the url of a page that allows a user to choose a file on the server. This page will be opened in a new window.
These arguments will be added to the url CKEditor=editor&CKEditorFuncNum=2&langCode=en-gb
CKEditor is the current editor
CKEditorFuncNum is the function to call(pass this value to callFunction)
langCode is the language
in the popup window call
window.opener.CKEDITOR.tools.callFunction(CKEditorFuncNum, 'img_url');
to set the selected image and optionally window.close(); to close the window.
e.g.
<?php
$files = glob('/images/directory/*.{jpg,png,gif,bmp}', GLOB_BRACE);
if (count($files) > 0){
echo 'Select a file <ul>';
foreach ($files as $file) {
echo '<li><button onclick="select(this)" data-name="'.$file.'">.basename($file).</button></li>';
}
echo '</ul>';
}
?>
<script>
function select(el){
window.opener.CKEDITOR.tools.callFunction(<?php echo (int)$_GET['CKEditorFuncNum'] ?>, el.getAttribute('data-name'));
window.close();
}
</script>
filebrowserUploadUrl will be the url that handles the image upload.
Its just a standard file upload handler except you run some js on the page.
and same arguments are added to the url as with filebrowserBrowseUrl.
<?php
... handle the upload
?>
<script>
window.parent.CKEDITOR.tools.callFunction(<?php echo (int)$_GET['CKEditorFuncNum'], ', ', json_encode($uploaded_image_url), ', ', json_encode($message_on_failure) ?>);
</script>";
Simple Demo http://jsfiddle.net/mowglisanu/f2ztp/show/ (upload doesn't actually work though)
http://jsfiddle.net/mowglisanu/f2ztp/
http://jsfiddle.net/mowglisanu/GuA6s/show/
http://phpfiddle.org/api/run/dv4-e70
Related
while download file using codeigniter in IE it redirects image path with out showing any popup like firefox or chrome to download file
code I am using in my controller:
public function download_file($filename)
{
$this->load->helper('download'); //load helper
$data = file_get_contents('wall-images/'.$filename); // Read the file's contents
$name = $filename;
force_download($name, $data);
}
I use javascript & it works for all browsers.
<a target="_blank" class="btn btn-primary" id="download" href="#">Download File</a>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#download').click(function(){
var url = "<?php echo site_url($filename); ?>";
document.location = url;
});
});
</script>
IE does not support neither navigating to a data URI nor the download attribute.
You can use navigator.msSaveBlob to save file for IE 10+.
You can check window.navigator.msSaveBloband write IE specific Code otherwise use existing code to save file.
You can check following link for more details:
Saving files locally using Blob and msSaveBlob
im making currently making my thesis about a record management of our university secretary.. in which all papers inside the office will be scanned and uploaded in the system.. i am using codeigniter..one of the feature in my system is to view the pdf file in other window of the browser. but my problem is, when i click the title. only blank page will be displayed in the other tab.. can you help me solve this one?? here is my code
controller:
function viewMinutesFile(){
if(isset($_GET['id'])){
$id = $_GET['id'];
$file = $this->minutes_model->getFile($id);
$fp= fopen($file->path, "r");
header("Cache-Control: maxage=1");
header("Pragma: public");
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=".$file->filename."");
header("Content-Description: PHP Generated Data");
header("Content-Transfer-Encoding: binary");
header('Content-Length:' .filesize($file->path));
ob_clean();
flush();
while (!feof($fp)){
$buff = fread($fp,1024);
print $buff;
}
exit;
}
}
code to open the file: this is my syntax to be clicked by the user so that pdf file will be open in the new tab
File
index.php/admin/viewMinutesFile?
id=" target="_tab">
try this one with a static url. no need any extra words for that.
Show My Pdf
New Update
if its work for you then fetch pdf name from database and put the name in the view like
Show My Pdf
now in the controller
$this->load->helper('download');
if($this->uri->segment(3))
{
$data = file_get_contents('./file_path/'.$this->uri->segment(3));
}
$name = $this->uri->segment(3);
force_download($name, $data);
well, you could add a link to file with target="_blank", like
<a href="<?php echo base_url(). 'your_controller/viewMinutesFile'; ?>" target="_blank">
View Pdf
</a>
and in controller function:
function viewMinutesFile(){
....
$file = $this->minutes_model->getFile($id);
$this->output
->set_content_type('application/pdf')
->set_output(file_get_contents($your_pdf_file));
}
you can try this on your view :
Filename
and on your controller, you can try this, because this is works for me :
function viewfile(){
$fname = $this->uri->segment(3);
$tofile= realpath("uploaddir/".$fname);
header('Content-Type: application/pdf');
readfile($tofile);
}
hope this might help you...
Just create a link to a blank page and use this code in your controller:
public function myPdfPage(){
$url = base_url('assets/your.pdf');
$html = '<iframe src="'.$url.'" style="border:none; width: 100%; height: 100%"></iframe>';
echo $html;
}
Enjoy!
There is no any problem with your code you can open easily on next tab, like other pages only difference you have to change header description and it is make sure on your browser pdf reader add-ons are available, otherwise it will give you option to download.
You may just follow this.
<?php echo form_open_multipart('your_controller/your_function','target="_blank"') ;?>
//other input fields
<?php form_close();?>
I want to close Colorbox from a controller. I used this code but it will not work:
<?= "$(document).ready(function() { $.colorbox.close(); });"; ?>
To me they are two options:
a)(Easy) inside your controller print js , example:
echo "<script type='text/javascript'> parent.$.fn.colorbox.close(); </script>";
but if you after redirects with redirect("yoursite"); codeigniter will show error , the other option is:
b) you need create in view a simple .php for example close_colorbox.php , inside write this code:
if (isset($script)) { echo $script; }
After in your controller include the next code:
$data['script'] = " <script type='text/javascript'> window.top.location.reload(); parent.$.fn.colorbox.close(); </script> ";
$this->load->vars($data);
$this->load->view('close_colorbox');
*note: window.top.location.reload(); is optional if you want reload the parent content
I'm developing a web application,after login the user is redirected to the inbox page,
where he will find many widgets, each with hundreds of records.
So it is taking too much time to open inbox page after login success.Very much performance issue.
So i want to display some(5-10) records in each widget
and after the page loads in the backend(user doesn't know) the request will be processing still and fetch the records and append them to the widget records.
Eg. If you open google images and search for cricket, it will display the page with images and if you scroll down only you will come to know the ajax request going and appending the response to the web page,
But it is not waiting till the entire page is loaded.
I must develop my application in the same way.
Any idea is Highly Appreciated and sample code too.
This should work for you, Mr.Chowdary.
You would need something to handle your requests in the backend. Since you did NOT specify whether you used Java or PHP or Python or whatever, I used PHP - its what I know best :D
PSEUDO CODE (loadmore.jsp)
Begin
widget = URL(widget) //the widget id or name
page = URL(page) //the page being retrieved
switch (widget)
{
case "widget1":
data_for_widget1 = paginated_query1(page)
print data_for_widget1
break
case "widget2":
data_for_widget2 = paginated_query2(page)
print data_for_widget2
break
default :
print "Invalid Widget"
break
}
End
PHP Version
<?php
if (isset($_GET['page'])) {
$widget = $_GET['page'];
$page = $_GET['page'];
switch ($widget) {
case "MyWidget1": //dynamic example
$manyManyItems; //A massive array of items
$pages = array_chunk($manyManyItems, 5); //break it up into chunks of 5 items
if( array_key_exists ($pages[$page]) )
for ($i = 0; $i < count($pages[$page]); $i++) { //load those chunks
echo '<div class="item">'.$pages[$page][$i].'</div>';
}
else {
echo "zero"; //code word that tells ajax that there is nothing more to load
}
break;
case "MyWidget2": //manual example
if($page==1) { //loads the first chunck manually
echo '<div class="item">dynamic content 1</div>';
echo '<div class="item">dynamic content 2</div>';
echo '<div class="item">dynamic content 3</div>';
}
elseif($page==2) { //loads the next batch
echo '<div class="item">dynamic content 1</div>';
echo '<div class="item">dynamic content 2</div>';
echo '<div class="item">dynamic content 3</div>';
}
else
echo "zero"; //code word that tells ajax that there is nothing more to load
break;
default:
echo "zero"; //code word that tells ajax that there is nothing more to load
}
}
?>
HTML
Each widget could look like this
<div id="MyWidget1" class="widget" data-widgetPage="0">
<div class="item">default content</div>
<div class="item">another default content</div>
...
<div class="loadmoreajaxloader" style="display:none;"><center>Loading...</center></div>
</div>
Javascript
<script type="text/javascript">
$(".widget").scroll(function()
{
if($(this).scrollTop() == $(this).height() - $(this).height())
{
var nextPage = eval($(this).attr("data-widgetPage") + 1);
$(this).find('.loadmoreajaxloader').show();
$.ajax({
url: "loadmore.php?widget="+$(this).attr("id")+"&page="+nextPage,
success: function(html)
{
if(html != "zero")
{
$(this).append(html);
$(this).('.loadmoreajaxloader').hide();
}else
{
$(this).find('.loadmoreajaxloader').html('<center>No more posts to show.</center>');
}
}
});
$(this).attr("data-widgetPage", nextPage);
}
});
</script>
Success with the app.
I got to know the following answer suits my requirement from the following site.. Jquery endless scrolling
I'm using Jquery colorbox to implement a popup windows. This pop-up is immediately open and it's working. But for the first loading page, just the first loading, the pop-up can't load the content.
jQuery(document).ready(function defaultPopup(){
var direct = '<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('popup')->toHtml(); ?>'
if(direct){
jQuery('#popup_home').colorbox({open:true,html:direct,overlayClose:false});
return false;
}
});
<div id="popup_home"></div>
You should escape special characters (<>) in your string.
For the web browser the content of your direct variable is an HTML tag without content.
Try this:
jQuery(document).ready(function defaultPopup(){
var direct = '<?php echo $this->getLayout()->createBlock(\'cms/block\')->setBlockId(\'popup\')->toHtml(); ?>'
direct = $('<div/>').text(direct).text() // escaping characters in the initial string
if(direct){
jQuery('#popup_home').colorbox({open:true,html:direct,overlayClose:false});
return false;
}
});
<div id="popup_home"></div>