<?php
/*
* Build preview html
*/
// BROWSER COMPLIANT IMAGE FILES
if (ereg("image/gif", $mime) || ereg("image/jpeg", $mime) || ereg("image/bmp", $mime)) {
$preview = "<IMG SRC='download.php?sub_dir=" . urlencode($_GET['sub_dir']) . "&file=" . urlencode($_GET['file']) . "'>";
}
// PLAYABLE MOVIE FILES
if (ereg("(^video/)", $mime)) {
$preview = "preview of " . $_GET['file'] . "<P>";
$preview .= "<EMBED class='embed' SRC='download.php?sub_dir=" . urlencode($_GET['sub_dir']) . "&file=" . urlencode($_GET['file']) . "' width='300' height='300' autoplay='false' controller='true' loop='true'>";
}
// PLAYABLE AUDIO FILES
if (ereg("(^audio/)", $mime)) {
$preview = "preview of " . $_GET['file'] . "<P>";
$preview .= "<EMBED class='embed' SRC='download.php?sub_dir=" . urlencode($_GET['sub_dir']) . "&file=" . urlencode($_GET['file']) . "' width='300' height='40' autoplay='false' controller='true' loop='true'>";
}
// READABLE TEXT FILES
if (ereg("^text/", $mime) || ereg("x-httpd-php", $mime) || $_GET['force_textview'] == 1) {
$preview = "<SPAN CLASS='fat'>Contents of " . $_GET['file'] . "</SPAN><BR>";
$preview .= "<TEXTAREA WRAP='OFF' CLASS='view-text'>";
// Risk HTML contamination on big files. PHP mem limit can kill proces if > 8 MB
if ($file_obj->size < 6291456) {
$fp = fopen($file, "r");
$contents = fread($fp, $file_obj->size);
$contents = htmlspecialchars($contents, ENT_QUOTES);
$preview .= $contents;
} else {
$fp = fopen($file, "r");
$contents = fread($fp, 5000000);
$contents = htmlspecialchars($contents, ENT_QUOTES);
$preview .= $contents;
}
$preview .= "</TEXTAREA>";
}
// HEXDUMP
if ($_GET['force_hexview'] == 1) {
$preview = "";
$preview .= "<table border=0 width='$table_width'>";
$preview .= "<tr><td align='left'><tt>";
$preview .= "<b>Dec.</b>";
$preview .= "</tt></td><td align='left'><tt>";
$preview .= "<b>Hexadec.</b>";
$preview .= "</tt></td><td align='left'><tt>";
$preview .= "<b>Hexadecimal data</b>";
$preview .= "</tt></td><td align='left'><tt>";
$preview .= "<b>Printable (ASCII) data</b>";
$preview .= "</tt></td></tr>";
$preview .= "<tr><td colspan=4><hr></td></tr>";
$icount=0;
$handle = fopen ($file, "rb");
if ($handle) {
while (!feof($handle)) {
$data=fread($handle, 16);
$hexdata= bin2hex($data);
$preview .= "<tr><td align=right><tt>";
$preview .= $icount . " " . " ";
$preview .= "</tt></td><td><tt>";
$preview .= dec2hex($icount, 8) . " " . " ";
$preview .= "</tt></td><td><tt>";
for ($j=0;$j<strlen($hexdata);$j+=2){
$preview .= substr($hexdata,$j,2);
$preview .= " ";
}
$preview .= " " . " ";
$preview .= "</tt></td><td><tt>";
for ($i=0;$i<strlen($hexdata);$i+=2) {
$preview .= htmlspecialchars(preg_replace('([^_a-zA-Z0-9\<\>\\\|\(\)\ \@\-\.])', '.', chr(hexdec(substr($hexdata,$i,2)))));
}
$preview .= "</tt></td></tr>";
$icount += 16;
}
}
fclose ($handle);
$preview .= "<tr><td colspan=4><hr></td></tr>";
$preview .= "</table><br>";
}
?>