I'm working on creating a Dynamic PHP Directory Reader that creates an AJAX linked list of all files in the directory where users can click and auto load CKeditor with page content and preview at the same time.
Help: I'm at a lost when it comes to dynamically uploading a new html file into the ckeditor. I have posted my PHP code below.
The layout:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> <script type="text/javascript" src="../ckeditor/ckeditor.js"></script> <script> function processAjax(url) { if (window.XMLHttpRequest) { // Non-IE browsers req = new XMLHttpRequest(); req.onreadystatechange = targetDiv; try { req.open("GET", url, true); } catch (e) { alert(e); } req.send(null); } else if (window.ActiveXObject) { // IE req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = targetDiv; req.open("GET", url, true); req.send(); } } return false; } function targetDiv() { if (req.readyState == 4) { // Complete if (req.status == 200) { // OK response document.getElementById("myDivName").innerHTML = req.responseText; // Tried to dynamically load textarea with no luck :-( //document.frmload.editor1.value = req.responseText; } else { alert("Problem: " + req.statusText); } } } </script> </head> <body> <table width="950"> <tr> <td valign="top" style="border-right:solid 2px green;margin: 0 0 0 10px;padding:0 10px 0 0 ;"> <b>Choose File:</b><br /> <?php $path = "."; $narray=array(); $dir_handle = @opendir($path) or die("Unable to open $path"); //echo "Edit File:<br/>"; $i=0; while($file = readdir($dir_handle)) { if(is_dir($file)) { continue; } else if($file != '.' && $file != '..') { //echo "<a href='$path/$file'>$file</a><br/>"; $narray[$i]=$file; $i++; } } sort($narray); for($i=0; $i<sizeof($narray); $i++) { $filename = str_replace(".htm", "", $narray[$i]); echo "<a onclick='return processAjax(this.href)' href=".chr(34).$narray[$i].chr(34).">".$filename."</a><br/>"; } //closing the directory closedir($dir_handle); ?> </td> <td valign="top" style="margin:0px;padding:0 0 0 10px;"> <!-- This <fieldset> holds the HTML that you will usually find in your pages. --> <form id="frmload" method="post"> <textarea id="editor1" name="editor1"><p>Initial 2 value.</p></textarea> <script type="text/javascript">CKEDITOR.replace( 'editor1' );</script> <p><input type="submit" value="Submit"/></p> </form> <div id="myDivName"></div> </td> </tr> </table> </body> </html>
Re: Newbie: Dynamic PHP Directory Reader with CKeditor
I have been working on this all day with still no luck - been reading up on the "CKeditor.ajax." examples but still nothing - This a great app just the documentation is limited and I noticed there are not to many replies within the community. Can someone shine some light on how to use the ajax module or paste some code to point me in the right direction. Calling it a night
CJ
Re: Dynamic PHP Directory Reader with CKeditor
It's been a few days and still no luck
I have read a ton of documentation on this site but nothing tells me what I need todo. Based on the board I'm trying to create a generic php pluging that can be incorporated into any php sites so my web clients can edit their own content. Hmm anyone got something like this working and if so willing to sell $ pluging codebase to use. I just want a cost estimate to see if this is really worth me spending additional time with it..
Again thanks all but still no luck ;-(
CJ