/************************************************************************
//
// DirectoryMediaIndex (dmi) 1.1
//
// This PHP script draws a DirectoryIndex of thumbnails for the
// following types of digital media files:
//
// JPEG
// PNG
// GIF
// MPEG
//
// For most uses you should just be able to place this script in a
// directory that contains the types of files listed above and is
// readable and writable by the webserver. You can do any custom
// configuration below.
//
// This script is for use with only PHP 4.0 and higher http://www.php.net
// It also depends on the ImageMagick (http://www.imagemagick.org)
// If you want to support MPEG movies too, you'll also need the following:
// mpgtx (http://mpgtx.sourceforge.net)
// dumpmpeg (http://sourceforge.net/projects/dumpmpeg/)
// SDL (http://www.libsdl.org/)
// SMPEG (http://www.lokigames.com/development/smpeg.php3)
//
// 2001-10-24 Tony J. White tjw@tjw.org
//**********************************************************************/
/**** CONFIGURATION *****/
// do you want ANYONE to be able to upload files throught this script?
$ALLOW_UPLOAD = 0;
// how many thumbnails per table_row?
$WIDTH = 6;
// what are the max dimensions for thumbnails? note that the aspect ratio
// of the images will NOT be changed. Setting either height or width very
// large will cause the lesser dimension to be used, this is nice for
// providing consistency for a better looking table.
$THUMB_WIDTH = 2000;
$THUMB_HEIGHT = 120;
// you need the FULL path here if this file is not in the same dir as
// your images, leave blank otherwise
$PHOTO_DIR = dirname(__FILE__);
// virtual path to the photos, leave blank if they are in the same virtual path
// as this script is.
$WEB_PHOTO_DIR = "";
// this is the path to ImageMajick's convert program.
#$CONVERT_PROG = "/usr/local/bin/convert";
$CONVERT_PROG = "/usr/bin/convert";
// this is the path to David Hedbor's dumpmpeg
// http://sourceforge.net/projects/dumpmpeg/
#$DUMPMPEG_PROG = "/usr/local/bin/dumpmpeg";
$DUMPMPEG_PROG = "";
// this is the path to mpgtx's mpginfo
// http://sourceforge.net/projects/mpgtx/
#$MPGINFO_PROG = "/usr/local/bin/mpginfo";
$MPGINFO_PROG = "";
// dump every N frames from the MPEG to be used in the animated GIF thumb.
// 30 means dump every 30th frame, good for full motion NTSC mpegs
// set it higher if your mpegs have alot of frames or you'll get huge
// thumbnail GIF's
$MPEG_FRAME_FREQ = 30;
// number of 1/100ths of a second to wait between frames in GIF animation
// thumbmails.
$ANIM_DELAY = 100;
/***** END CONFIG *****/
// Fixes the register_global issue with this script
if(isset($_REQUEST["thumb"])){
$thumb = $_REQUEST["thumb"];
}
if(isset($_REQUEST["name"])){
$name = $_REQUEST["name"];
}
//$thumb="true";
//$name="20120204_002.jpg";
//if(isset($_REQUEST[""])){
// $thumb = $_REQUEST[""];
//}
// End fixes
// handles spaces and such
function shellWrap($in) {
return str_replace("\n", "\\", preg_replace("/([ \'\"&;\`\(\)?!])/",
"\n\\1", $in));
}
// gets filename without extension
function getFileName($in) {
$out = basename($in);
$out = substr(strrev(strstr(strrev($out), ".")), 0, -1);
return $out;
}
function safeFileName($in) {
return preg_replace("/[^a-z0-9\.]/i", "_", $in);
}
function stripExtension($in) {
// if(eregi("(.+)\.[a-z]{3,4}$", $in, $out)) {
if(preg_match("/(.+)\.[a-z]{3,4}$/", $in, $out)) {
return $out[1];
}
else return $in;
}
// helper function for interpreting getImageSize() return data
function extensionize($in, $type) {
if($type == 1) {
if(!eregi(".gif$", $in)) return $in.".gif";
}
elseif($type == 2) {
if(!eregi(".jpg$", $in)) return $in.".jpg";
}
elseif($type == 3) {
if(!eregi(".png$", $in)) return $in.".png";
}
elseif($type == 4) {
if(!eregi(".swf$", $in)) return $in.".swf";
}
return $in;
}
// helper function for interpreting getImageSize() return data
function getExtension($type) {
if($type == 1) return ".gif";
elseif($type == 2) return ".jpg";
elseif($type == 3) return ".png";
elseif($type == 4) return ".swf";
return "";
}
// helper function for interpreting getImageSize() return data
function getMimeType($type) {
if($type == 1) return "image/gif";
elseif($type == 2) return "image/jpeg";
elseif($type == 3) return "image/png";
elseif($type == 4) return "application/x-shockwave-flash";
return "";
}
function is_mpeg_video($filename) {
if(!is_executable($GLOBALS["MPGINFO_PROG"])) return 0;
$is_mpeg = 0;
$cmd = $GLOBALS["MPGINFO_PROG"]." ".shellWrap($filename);
$out = `$cmd`;
$out = str_replace("\r", "", $out);
$lines = explode("\n", $out);
while(list($num, $line) = each($lines)) {
if(preg_match("/^ Mpeg .*Video/", $line)) $is_mpeg = 1;
}
return $is_mpeg;
}
// this function is the replacement for /bin/find to make things a
// little safer and to possibly allow windows portability
function getListing() {
if(!is_dir($GLOBALS["PHOTO_DIR"])) {
echo "ERROR: ".$GLOBALS["PHOTO_DIR"]." is not a "
." directory!
";
return 0;
}
$dir_handle = opendir($GLOBALS["PHOTO_DIR"]);
while($file = readdir($dir_handle)) {
if($file == ".." || $file == ".") continue;
$full_file = $GLOBALS["PHOTO_DIR"]."/".$file;
$img_info = @getImageSize($full_file);
if(is_array($img_info)) {
$files[] = $file;
$thumb_info = @getImageSize($GLOBALS["PHOTO_DIR"]
."/thumbs/".stripExtension($file)."_thumb"
.getExtension($image_info[2]));
if(is_array($thumb_info))
$thumb_infos[] = $thumb_info;
else $thumb_infos[] = "";
}
elseif(is_mpeg_video($file)) {
$files[] = $file;
$thumb_info = @getImageSize($GLOBALS["PHOTO_DIR"]
."/thumbs/".stripExtension($file)."_thumb.gif");
if(is_array($thumb_info))
$thumb_infos[] = $thumb_info;
else $thumb_infos[] = "";
}
$img_info = "";
$thumb_info = "";
}
$my_return = array($files, $thumb_infos);
// echo "
"; print_r($files); echo ""; die(""); // echo "
"; print_r($my_return); echo ""; die(""); return $my_return; // return array($files, $thumb_infos); } function clearBitmaps($dump_dir) { if(!is_dir($GLOBALS["PHOTO_DIR"]."/thumbs/".$dump_dir)) { return 0; } $full_dump_dir = $GLOBALS["PHOTO_DIR"]."/thumbs/".$dump_dir; $bmp_dir_handle = opendir($full_dump_dir); while($file = readdir($bmp_dir_handle)) { if($file == ".." || $file == ".") continue; $full_file = $GLOBALS["PHOTO_DIR"] ."/thumbs/".$dump_dir."/".$file; if(eregi("\.bmp$", $full_file)) $deleted = unlink($full_file); } $success = @rmdir($full_dump_dir); return $success; } function errorImage() { header("Content-type: image/gif"); // this image is image1.gif blatently ripped off from the // apache icons directory $image = "R0lGODlhFAAWAOMAAP/////MM/9mZsz//8zMzJmZmZlmADMzMwAA" ."AAAAAAAAAAAAAAAAAAAAAAAAAAAAACH+TlRoaXMgYXJ0IGlzIGlu" ."IHRoZSBwdWJsaWMgZG9tYWluLiBLZXZpbiBIdWdoZXMsIGtldmlu" ."aEBlaXQuY29tLCBTZXB0ZW1iZXIgMTk5NQAh+QQBAAADACwAAAAA" ."FAAWAAAEbXDISSm6NVckOtLg5YEZQgTcR1oBqq6S2RovjLQYHJ8BT" ."R2FoFB4cwUPkgNgyWReeghAQaVsNi+X5TRpvWa11K4zytwOqoCoOm" ."01V8nicphthYO59Pj9vLT323NYgl1ueoRUQEOKQwc1go+QKhEAOw" ."=="; echo base64_decode($image); exit(); } // auto config if($PHOTO_DIR == "") $PHOTO_DIR = dirname(__FILE__); if($WEB_PHOTO_DIR == "") $WEB_PHOTO_DIR = $_SERVER['REQUEST_URI_PATH']; if($CONVERT_PROG == "") $CONVERT_PROG = "convert"; if($DUMPMPEG_PROG == "") $DUMPMPEG_PROG = "dumpmpeg"; if($MPGINFO_PROG == "") $MPGINFO_PROG = "mpginfo"; if($MPEG_FRAME_FREQ == "") $MPEG_FRAME_FREQ = 30; if($ANIM_DELAY == "") $ANIM_DELAY = 100; // main actions if(isset($upload) && $upload && $ALLOW_UPLOAD) { $success = 0; $img = getImageSize($new_file); // If this isn't a JPG/GIF/PNG use ImageMajik to convert // whatever it is to a jpg if(!is_uploaded_file($new_file)) { $img = ""; } elseif(!is_array($img) && is_mpeg_video($new_file)) { $new_name = basename($new_file_name); $new_name = stripExtension($new_name); $new_name = safeFileName($new_name); $new_name = $new_name.".mpg"; $success = move_uploaded_file($new_file, $PHOTO_DIR."/".$new_name); } elseif(!is_array($img)) { $tmp_name = basename($new_file_name); $tmp_name = safeFileName($tmp_name); $new_name = stripExtension($tmp_name).".jpg"; move_uploaded_file($new_file, $PHOTO_DIR."/".$tmp_name); $cmd = "$CONVERT_PROG $PHOTO_DIR/".shellWrap($tmp_name) ." $PHOTO_DIR/".shellWrap($new_name); //echo $cmd; `$cmd`; unlink($tmp_name); if(file_exists($PHOTO_DIR."/".$new_name)) $success = ($img = getImageSize($new_name)); else $img = ""; } else { $new_name = basename($new_file_name); $new_name = stripExtension($new_name); $new_name = safeFileName($new_name); $new_name = extensionize($new_name, $img[2]); $success = move_uploaded_file($new_file, $PHOTO_DIR."/".$new_name); } if(!$success) { echo "ERROR: uploaded file is not a recoginzied " ." image file format!"; } } if(!isset($_REQUEST["thumb"])) { $thumb = $_REQUEST["thumb"]; if(file_exists("header.php")) include("header.php"); $listing = getListing(); $files = $listing[0]; $thumb_infos = $listing[1]; sort($files); $my_table = ""; $my_table .= "
| ";
$my_table .= "";
$my_table .= " "; $my_table .= ucwords( str_replace("_", " ", getFileName($files[$i]))); $my_table .= " | ";
$cell_count++;
$i++;
}
// fill up all the empty sells
for($i=$cell_count;$i<$WIDTH;$i++) {
$my_table .= ""; } $my_table .= " |