Jump to content

S Murder

Members
  • Posts

    101
  • Joined

  • Last visited

Everything posted by S Murder

  1. listfiles.inc (works)<?php function make_file_list($dir="") { if($dir == "") { $dir = $_SERVER["DOCUMENT_ROOT"]; } $dirAry = scandir($dir); foreach($dirAry as $value) { $fullpath = $dir . DIRECTORY_SEPARATOR . $value; if(is_dir($value)) { //Write list item echo '<li id="'.$fullpath.'" onclick="showInfo(this)" ondblclick="refreshFileList(this)">'; echo '<span onclick="refreshFileList(parent)" class="expandIcon">+</span>'; echo '<img src="media/dir.ico" width="16px" height="16px" alt="Directory"/> '; echo $value; echo '<ul></ul>'; echo "</li>\n"; } elseif(is_file($value)) { //Write list item echo '<li id="'.$fullpath.'" onclick="showInfo(this)" ondblclick="showFile(this)">'; echo '<span class="expandVoid"></span>'; echo '<img src="media/file.ico" width="16px" height="16px" alt="File"/> '; echo $value; echo '<ul></ul>'; echo "</li>\n"; } else { //Write list item echo '<li id="'.$fullpath.'" onclick="showInfo(this)" ondblclick="showFile(this)">'; echo '<span class="expandVoid"></span>'; echo '<img src="media/vlc.ico" width="16px" height="16px" alt="Other"/> '; echo $value; echo '<ul></ul>'; echo "</li>\n"; } } } make_file_list($_POST["dir"]);?> showfile.inc (doesn't work) (I changed the post value from "dir" to "file_name"). <?php //Extension lists $txtExts = '.css,.cgi,.htm,.html,.js,.log,.php,.php3,.pl,.shtml,.txt'; $imgExts = '.bmp,.gif,.jpg,.jpeg,.ico,.png,.tiff'; $flashExts = '.swf'; $mediaExts = '.acc,.asf,.avi,.mov,.mp3,.mp4,.qt,.wma,.wmv'; function make_txt_editor() { echo '<form name="txtEditor" action="java script:saveFile();" method="GET">'."\n"; echo '<textarea></textarea>'."\n"; echo '<input type="submit" value="Save Changes"/>'."\n"; echo '</form>'."\n"; } function examine_ext($file_name) { echo "File name: ".$file_name; echo "test"; $extIndex = strpos($file_name, '.'); if($extIndex < 0) { $ext = ''; echo "no extension"; } else { $ext = substring($file_name, $extIndex); echo $ext; } //If there's no extension if($ext == '') { make_txt_editor(); } //If the extension is for a txtx file if(strpos($txtExts, $ext) != -1) { make_txt_editor(); } //If the extension is for an image file if(strpos($imgExts, $ext) != -1) { make_img(); } //If the extension is for a flash file elseif(strpos($flashExts, $ext) != -1) { make_flash_obj(); } //If the extension is for another media file elseif(strpos($mediaExts, $ext) != -1) { make_media_obj(); } //Open in text editor as last ditch effort else { make_txt_editor(); } } examine_ext($_POST["file_name"]);?> In showfile.inc, the 2 echo statements in examine_ext($file_name) work so I know the function is successfully being called, but no value is displayed for file_name.When the echo statement is outside the function, no value is displayed there either.
  2. The listitem and newListitem are both <li> elements being passed in the parameters. I just changed the name to newlistitem because that code block requires that the global listitem variable be updated.When the alert is used it correctly shows the id.I've also tried var sendData = "dir=foo"; in the second code block and foo isn't passed to showfile.inc either.
  3. I'm able to get the following code to work: //This code displays the file lists function refreshFileList(newListitem) { client = GetXmlHttpObject(); listitem = newListitem; list = this.listitem.getElementsByTagName("ul")[0]; listitem.childNodes[0].innerHTML = "-"; client.open("POST", "listfiles.inc", true); client.setRequestHeader("If-Modified-Since","Sat, 01 Jan 2000 00:00:00 EST"); client.onreadystatechange = dirListUpdate; var sendData = "dir=" + listitem.id; client.send(sendData); } function dirListUpdate() { //alert(client.readyState); if(client.readyState == 4 || client.readyState == "complete") { //alert(client.responseText); list.innerHTML = client.responseText; } } But this code doesn't: //This code displays the selected file function showFile(newListitem) { client = GetXmlHttpObject(); client.open("POST", "showfile.inc", true); client.setRequestHeader("If-Modified-Since","Sat, 01 Jan 2000 00:00:00 EST"); client.onreadystatechange = fileViewerUpdate; var sendData = "dir=" + newListitem.id; //alert(listitem.id); client.send(sendData); } function fileViewerUpdate() { //alert(client.readyState); if(client.readyState == 4 || client.readyState == "complete") { //alert(client.responseText); fileViewer.innerHTML = client.responseText; } } I've tracked the problem, and for some reason it seems to be that in showfile.inc (the .inc files are php) the post value of dir has no value. Anybody have any ideas why? Is it probably a Javascript problem or a php problem?
  4. Nevermind. I just found a few syntax problems and fixed them (used "this" in the wrong place, so itemlist was never set globally).
  5. I'm told you're supposed to put it in because older browsers that don't understand javascript will ignore your code, while newer ones will still look for the javascript code in the comments.Either way, the javascript can still produce alerts, which means it's working.I've modified it some more, but it still won't work.var client = new XMLHttpRequest() function doStuff(listitem) { client.open("GET", "http://www.rit.edu/~sth5208/admin/test.php3", true) client.setRequestHeader("If-Modified-Since","Sat, 01 Jan 2000 00:00:00 EST") client.onreadystatechange = xmlUpdate(listitem) alert("test1") client.send(null) alert("test2"); } function xmlUpdate(listitem) { alert(client.readyState) if(client.readyState == 4 || client.readyState == "complete") { alert(client.responseText) listitem.innerHTML = client.responseText } }All the alerts show up, but the alert in xmlUpdate() displays 1. Also, the alert in xmlUpdate shows up before the other 2.
  6. I'm new to AJAX and am just experimenting to see how it works. I got the following code to work:<script type="text/javascript" language="javascript"> <!-- var client = new XMLHttpRequest() function doStuff(listitem) { client.open("GET", "http://www.rit.edu/~sth5208/admin/test.php3", true) client.send(null) client.onreadystatechange = xmlUpdate(listitem) //alert("test") } function xmlUpdate(listitem) { //alert("test") if(client.readyState == 4 || client.readyState == "complete") { //alert(client.responseText) listitem.innerHTML = client.responseText } } --> </script>Where doStuff() is called when you click on a list item, passing a reference to itself. The problem is, after I commented out the alert statements in xmlUpdate(listitem) it stopped working, and when I uncomment them it works again. Any suggestions?
×
×
  • Create New...