Good day to you all,
Session are always fun, this time I pushing 2 array to a session, one a list of folder and the other a list of files :
PHP Code:
<?php
session_start();
?>
function ahah(url, target) { document.getElementById(target).innerHTML = ' Retreiving and loading image... <br/> Recherche et chargement de l\'image...'; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } if (req != undefined) { req.onreadystatechange = function() {ahahDone(url, target);}; req.open("GET", url, true); req.send(""); } }
function ahahDone(url, target) { if (req.readyState == 4) { // only if req is "loaded" if (req.status == 200) { // only if "OK" document.getElementById(target).innerHTML = req.responseText; } else { document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText; } } }
function load(name, div) { ahah(name,div); return false; }
echo "<ul id=\"".preg_replace('/\//','_',substr($directory,0,strlen($directory)-1))."\">\n"; //start a new unordered list for every iteration through dirList
$dircor = $directory; // tidy up: close the handler closedir($handler); foreach($folders as $folder=>$file) {
echo "<li id=\"pic\"><div class=\"folder\">".$folder_modified[$folder]."</div>"; //echo the folder name enclosed in a list item dirList($directory.$file.'/'); //loop through the contents of $folder echo "</li>\n"; //close this list item after all files and folders in $folder have been looped through
}
foreach($files as $key=>$file) {
echo "<li id=\"pic\"><a href=\"index.html\" onclick=\"load('image_view.php?dir=".$dircor."&file=".$file."','boxdisp');return false;\"> ".$file_modified[$key]."</a></li>\n"; //echo the file name enclosed in a list item }
echo "</ul>\n"; //close the unordered list } $_SESSION['folders']=$folders; $_SESSION['files']=$files;
dirList($directory);
When you click on a folder it bring
you to a page like that :