====Image Listing==== This action (and associated class code) allows the directory/file tree of the image files in the upload directory specified in the config file to be shown. There are two files. The first is directory.php which should be placed in the actions directory. The second is FileDisplayClass.inc.php which is a modification of a class file obtained from www.phpclasses.org. If a thumbnail gallery is desired or necessary, see the code at GmBowen...this action was developed to support those who do not have GD on their servers but for whom a listing of uploaded images may be useful. **Use:** Place ""{{directory}}"" on a page to obtain the listings of uploaded image files (in the directory as specified by wakka config). **Note:** The code was developed to support a course I'm teaching where thumbnail galleries were unnecessary. This code is (a) not optimized (there's some unused functions that could be stripped from the class, unused variables passed across to the functions, etc), (b) allows images to be opened in a new window (using target=_BLANK) which some people consider to be a poor approach, and (c) it needs a URL to be set manually in the class file (sorry, I couldn't figure out how to do it in a function....feel free to fix it if you know how). Place this code in the actions directory as ##directory.php## %%(php) config["base_url"].$this->MiniHref($method, $tag); $fldr=$_GET['fldr']; $fldr=strip_tags($fldr); if ($fldr) {echo "<< Back <<";} else {echo "Click on a directory name to see a list of files.";} $activefolder = $this->config["upload_path"]."/".$fldr; require_once('scripts/FileDisplayClass.inc.php'); $FileDisplay = New FileDisplay; $FileDisplay->showContents($activefolder, $link, $fldr); if ($fldr) {echo "<< Back <<";} else {echo "  ";} ?> %% Place this code in a directory called ##scripts## placed in wikka root named as ##FileDisplayClass.inc.php##... %%(php) getColNum(); if(strlen($targetdir) == 0) { $showdir = $this->rootdir; } else { $getrootdir = substr($targetdir, 0, strlen($this->rootdir)); // This checks to see if the rootdir is a sub string of the target directory if($this->rootdir == $getrootdir){ $showdir = $targetdir; } else { $targetdir = $this->rootdir; $showdir = $targetdir; } } ?> showperms){ $this->maketableheader("Permissions"); } if($this->showsize){ $this->maketableheader("File Size"); } if($this->showtype){ $this->maketableheader("Type"); } if($this->showmodified){ $this->maketableheader("Date Modified"); } ?> getDirContents($this->rootdir,$targetdir,$link,$inputtype); ?>
File Name
checkext($diritem)){ $dirempty = false; $newtarget = $targetdir . "/" . $diritem; $additem = true; } } elseif(is_dir($targetdir . "/" . $diritem) && ($diritem != ".") && ($diritem != "..")) { $dirempty = false; $newtarget = $link . $targetdir . $diritem; $additem = true; } if($additem){ $this->arrdircontents[] = array( "fullpath" => $newtarget, "filename" => $diritem, "filesize" => filesize($fullpath), "type" => filetype($fullpath), "fileperms" => $this->convertperms(fileperms($fullpath)), "filemodified" => date("Y-m-d H:i:s", filemtime($fullpath)), "fileicon" => $this->selectfileicon($diritem,filetype($fullpath)) ); } } closedir($dir); if($dirempty){ ?> Directory is empty
arrsortkeys; $this->aasort($this->arrdircontents, array($arrsortkeys)); $this->printFileInfo($fullpath, $link, $piclink); } $prevdir = substr($targetdir, 0, strrpos($targetdir, "/")); ?> rootdir) { echo ""; } else { echo(" "); } ?> arrdircontents as $sdiritem){ ?> checkext($sdiritem["filename"])=="0") { $link = $wakka->config["base_url"].$wakka->MiniHref($method, $tag)."&fldr=".$sdiritem["filename"]; echo "".htmlspecialchars($sdiritem["filename"]).""; } else { $fldr = $_GET['fldr']; $pix=$wakka->config["upload_path"]."/".$fldr."/".$sdiritem["filename"]; echo "".htmlspecialchars($sdiritem["filename"]).""; // THE LINE BELOW NEEDS THE CORRECT URL TO BE SET!!!!! $pix2 = "http://131.202.167.33/3511wiki/".$pix; echo "  [link]"; } echo ""; if($this->showperms){ $this->maketablecell($sdiritem["fileperms"]); } if($this->showsize){ if($this->checkext($sdiritem["filename"])=="0") { $this->maketablecell("N/A"); } else { $this->maketablecell($this->convertFileSize($sdiritem["filesize"])); } } if($this->showtype){ $this->maketablecell($sdiritem["type"]); } if($this->showmodified){ $this->maketablecell($sdiritem["filemodified"]); } echo ""; } } function maketablecell($cellcontent) { echo(''); echo(htmlspecialchars($cellcontent)); echo(''); } function maketableheader($cellcontent) { echo(''); echo(htmlspecialchars($cellcontent)); echo(''); } function getColNum() { $this->colnum = 2; if($this->showsize){ $this->colnum += 1; } if($this->showtype){ $this->colnum += 1; } if($this->showmodified){ $this->colnum += 1; } if($this->showperms){ $this->colnum += 1; } } function aasort(&$array, $args) { foreach($args as $arg) { $order_field = substr($arg, 1, strlen($arg)); foreach($array as $array_row) { $sort_array[$order_field][] = $array_row[$order_field]; } $sort_rule .= '$sort_array['.$order_field.'], '.($arg[0] == "+" ? SORT_ASC : SORT_DESC).','; } eval ("array_multisort($sort_rule".' &$array);'); } function convertPerms($inperms) { $permstr; // holds the 'rwxrwxrwx' style permission string to be returned if($inperms & 0x1000) // FIFO pipe $permstr = 'p'; elseif($inperms & 0x2000) // Character special $permstr = 'c'; elseif($inperms & 0x4000) // Directory $permstr = 'd'; elseif($inperms & 0x6000) // Block special $permstr = 'b'; elseif($inperms & 0x8000) // Regular $permstr = '-'; elseif($inperms & 0xA000) // Symbolic Link $permstr = 'l'; elseif($inperms & 0xC000) // Socket $permstr = 's'; else // UNKNOWN $permstr = 'u'; // owner $permstr .= (($inperms & 0x0100) ? 'r' : '-') . (($inperms & 0x0080) ? 'w' : '-') . (($inperms & 0x0040) ? (($inperms & 0x0800) ? 's' : 'x' ) : (($inperms & 0x0800) ? 'S' : '-')); // group $permstr .= (($inperms & 0x0020) ? 'r' : '-') . (($inperms & 0x0010) ? 'w' : '-') . (($inperms & 0x0008) ? (($inperms & 0x0400) ? 's' : 'x' ) : (($inperms & 0x0400) ? 'S' : '-')); // world $permstr .= (($inperms & 0x0004) ? 'r' : '-') . (($inperms & 0x0002) ? 'w' : '-') . (($inperms & 0x0001) ? (($inperms & 0x0200) ? 't' : 'x' ) : (($inperms & 0x0200) ? 'T' : '-')); return $permstr; } function convertFileSize($inbytes) { if($inbytes < 1000){ return $inbytes . " bytes" ; } if($inbytes >= 1000) { $inbytes = $inbytes/1000; return number_format($inbytes) . " KB"; } } function checkext($inputstr){ if(strlen($this->extallow) > 0){ $inputstrlen = strlen($inputstr); $revstr = strrev($inputstr); $cutstr = $inputstrlen - strpos($revstr,"."); $inputsubstr = strtolower(substr($inputstr,$cutstr,$inputstrlen)); $arrExtAllow = explode(",", strtolower($this->extallow)); $extpass = false; foreach($arrExtAllow as $sExt){ if($sExt == $inputsubstr){ return true; $extpass = true; } } if($extpass == false) { return false; } } else { return true; } } function dirlinks($indirlinks) { $lastdir; $end; $i; $output; $arrDirLinks; $dirlink; $arrDirLinks = explode("/",$indirlinks); $end=count($arrDirLinks); $i=0; foreach($arrDirLinks as $dirlink){ $i = $i + 1; if($i == 1){ $lastdir = $dirlink; } else { $lastdir = $lastdir . "/" . $dirlink; } if ($i == $end){ if($i == 1){ $output = $dirlink; } else { $output = $output . "/" . $dirlink; } } else { if($i == 1) { $output = $output . $dirlink; } else { $output = $output . $dirlink; } } } return $output; } function selectfileicon($inputstr,$inputtype) { if($inputtype != "dir"){ $inputstrlen = strlen($inputstr); $revstr = strrev($inputstr); $cutstr = $inputstrlen - strpos($revstr,"."); $inputsubstr = substr($inputstr,$cutstr,$inputstrlen); switch ($inputsubstr) { /* case "PDF"; return "pdficon.png"; break; */ default; return ""; } } else { return ""; } } } ?> %% This is the directory in the designated upload directory root.... http://gmbtst.msvu.ca/wikitest/dirlist1.jpg This is the file listing in the associated page directory (shows image files only).... http://gmbtst.msvu.ca/wikitest/dirlist2.jpg This shows the pop-up with the URL of the image files highlighted.... http://gmbtst.msvu.ca/wikitest/dirlist3.jpg ---- CategoryUserContributions