Codice PHP:
//end part for showing a slideshow
//begin part for giving out zip archive of all photos:
//begin zip routine class based on and mostly equal to code found here:
//http://www.zend.com/zend/spotlight/creating-zip-files1.php
//some zip file format specification used from:
//http://www.pkware.com/business_and_developers/developer/popups/appnote.txt
class zipfile
{
var $ctrl_dir = array();
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
var $old_offset = 0;
var $new_offset = 0;
function add_dir($name)
{
$name = str_replace("\\", "/", $name);
$fr = "\x50\x4b\x03\x04";
$fr .= "\x0a\x00";
$fr .= "\x00\x00";
$fr .= "\x00\x00";
$fr .= "\x00\x00\x00\x00";
$fr .= pack("V",0);
$fr .= pack("V",0);
$fr .= pack("V",0);
$fr .= pack("v", strlen($name) );
$fr .= pack("v", 0 );
$fr .= $name;
$fr .= pack("V", 0);
$fr .= pack("V", 0);
$fr .= pack("V", 0);
$this->new_offset += strlen($fr);
echo $fr;
$cdrec = "\x50\x4b\x01\x02";
$cdrec .="\x00\x00";
$cdrec .="\x0a\x00";
$cdrec .="\x00\x00";
$cdrec .="\x00\x00";
$cdrec .="\x00\x00\x00\x00";
$cdrec .= pack("V",0);
$cdrec .= pack("V",0);
$cdrec .= pack("V",0);
$cdrec .= pack("v", strlen($name) );
$cdrec .= pack("v", 0 );
$cdrec .= pack("v", 0 );
$cdrec .= pack("v", 0 );
$cdrec .= pack("v", 0 );
$ext = "\x00\x00\x10\x00";
$ext = "\xff\xff\xff\xff";
$cdrec .= pack("V", 16 );
$cdrec .= pack("V", $this -> old_offset );
$cdrec .= $name;
$this -> ctrl_dir[] = $cdrec;
$this -> old_offset = $this->new_offset;
return;
}
function add_file($data, $name, $timedate) {
$name = str_replace("\\", "/", $name);
$unc_len = strlen($data);
$crc = crc32($data);
$zdata = $data;
$c_len = strlen($zdata);
$fr = "\x50\x4b\x03\x04";
$fr .= "\x14\x00";
$fr .= "\x00\x00";
$fr .= "\x00\x00";//no compression
$fr .= $timedate;//date stamp
$fr .= pack("V",$crc);
$fr .= pack("V",$c_len);
$fr .= pack("V",$unc_len);
$fr .= pack("v", strlen($name) );
$fr .= pack("v", 0 );
$fr .= $name;
$fr .= $zdata;
$fr .= pack("V",$crc);
$fr .= pack("V",$c_len);
$fr .= pack("V",$unc_len);
$this->new_offset += strlen($fr);
echo $fr;
$cdrec = "\x50\x4b\x01\x02";
$cdrec .="\x00\x00";
$cdrec .="\x14\x00";
$cdrec .="\x00\x00";
$cdrec .="\x00\x00";//no compression
$cdrec .= $timedate;//date stamp
$cdrec .= pack("V",$crc);
$cdrec .= pack("V",$c_len);
$cdrec .= pack("V",$unc_len);
$cdrec .= pack("v", strlen($name) );
$cdrec .= pack("v", 0 );
$cdrec .= pack("v", 0 );
$cdrec .= pack("v", 0 );
$cdrec .= pack("v", 0 );
$cdrec .= pack("V", 32 );
$cdrec .= pack("V", $this -> old_offset );
$this -> old_offset = $this -> new_offset;
$cdrec .= $name;
$this -> ctrl_dir[] = $cdrec;
}
function file() {
$ctrldir = implode("", $this -> ctrl_dir);
return
$ctrldir.
$this -> eof_ctrl_dir.
pack("v", sizeof($this -> ctrl_dir)).
pack("v", sizeof($this -> ctrl_dir)).
pack("V", strlen($ctrldir)).
pack("V", $this->new_offset).
"\x00\x00";
}
}//end zip routine class
function dosti($y, $n, $d, $h, $m, $s){
return (int)((int)(((int)$y - 1980) << 25) | (int)((int)$n << 21) |
(int)((int)$d << 16) | (int)((int)$h << 11) |
(int)((int)$m << 5) | (int)((int)$s >> 1));
}
if($QUERY_STRING!="" && sizeof($args)>=1 && $args[0]=="zipfile" && $allowZip!=false){
if(strlen($basePath)>2)
$dirnm=substr($basePath,0,strlen($basePath)-1);//full path but without final slash
else
$dirnm=dirname($_SERVER["SCRIPT_NAME"]);
$dirnm=substr($dirnm,strrpos($dirnm,"/"));
$dirnm=str_replace(array("\\","/"),"",$dirnm);
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=\"$dirnm.zip\"");
$dirnm.="/";
$zippi=new zipfile();
$zippi->add_dir($dirnm);
for($i=0;$i<sizeof($filter_files);$i++){
$imgData=file_get_contents($basePath.$filter_files[$i]);
$timestamp=filemtime($basePath.$filter_files[$i]);
$datetime=pack("V",dosti( date("Y",$timestamp),
date("n",$timestamp),
date("j",$timestamp),
date("G",$timestamp),
date("i",$timestamp),
(int)((int)(date("s",$timestamp)/2)*2) ));
$zippi->add_file($imgData,$dirnm.$filter_files[$i],$datetime);
}
echo $zippi->file();
die();
}
//end part for giving out zip archive of all photos:
//begin part for browsing through images:
function photosSize(){
global $filter_files;
global $basePath;
$fSum=0;
foreach($filter_files as $fn){
$fSum+=filesize($basePath.$fn);
}
return sprintf("%01.2f MB",(((int)((int)$fSum/1024))/1024));
}
if($QUERY_STRING!="" && sizeof($args)>=1 && is_numeric($args[0]))
$offset=((int)(intval($args[0])/$maxperpage))*$maxperpage;
else
$offset=0;
if($offset<0)
$offset=0;
if($offset>=sizeof($filter_files))
$offset=sizeof($filter_files)-(sizeof($filter_files) % $maxperpage);
echo "$doctype<html><head>$encoding<meta name=\"info\" content=\"Generated using PHPshow, available at phpshow.panmental.de\">";
echo $stylesheet."\r\n";
echo "<script type=\"text/javascript\">";
echo "<!--\r\n";
echo "function slides(){\r\n";
echo "self.location.href=\"$SCRNAME?$GD_WORKAROUND".$sep."slides$sep".$offset."\";\r\n";
echo "\r\n}
picTexts=new Array(".sizeof($filter_files).");
picLinks=new Array(".sizeof($filter_files).");\r\n";
browsePicMetaData();
echo "
var dontHide=false;
var lastNum=-1;
function showData(num,caller) {
infotxt=document.getElementById(\"infotext\");
if((picTexts[num])&&(picTexts[num]!=\"\")){
dontHide=true;
if(lastNum!=num){
lastNum=num;
infotxt.style.visibility=\"visible\";
x=caller.offsetParent;
tmpLeft=0;
while(x){
tmpLeft+=x.offsetLeft;
x=x.offsetParent;
}
infotxt.style.left=tmpLeft;
y=caller;
tmpTop=0;
while(y){
tmpTop+=y.offsetTop;
y=y.offsetParent;
}
infotxt.style.top=tmpTop+caller.offsetHeight+4;
infotxt.style.width=caller.offsetWidth-4;
if((picLinks[num])&&(picLinks[num]!=\"\")){
infotxt.innerHTML=\"[url='\"+picLinks[num]+\"']<span class='info'>\"+picTexts[num]+\"</span>[/url]\";
}
else
infotxt.innerHTML=\"<span class='info'>\"+picTexts[num]+\"</span>\";
}
}
else{
if(infotxt)
infotxt.style.visibility=\"hidden\";
lastNum=-1;
}
return false;
}
function doHide(){
dontHide=false;
hideData();
}
function hideData(){
if(!dontHide){
infotxt=document.getElementById(\"infotext\");
infotxt.style.visibility=\"hidden\";
lastNum=-1;
}
}
window.onresize = doHide;
";
if($allowZip){
$downloadString=str_replace(array("#SIZE#"),photosSize(),$downloadString);
$downloadString=str_replace(array("#NUM#"),sizeof($filter_files),$downloadString);
echo "function downloadExec(){
res=confirm(\"$downloadString\");
if(res)
self.location.href=\"$SCRNAME?zipfile\";\r\n}\r\n";
}
$priorPageLink="$SCRNAME?$GD_WORKAROUND$sep".strval($offset-$maxperpage);
$nextPageLink="$SCRNAME?$GD_WORKAROUND$sep".strval($offset+$maxperpage);
echo "
function keyControl(evnt){
if (!evnt)
evnt = window.event;
if (evnt.which) {
evntkeycode = evnt.which;
} else if (evnt.keyCode) {
evntkeycode = evnt.keyCode;
}
";
if($offset>0)
echo " if(evntkeycode==37)
location.href=\"$priorPageLink\";
";
if($offset+$maxperpage<sizeof($filter_files))
echo " if(evntkeycode==39)
location.href=\"$nextPageLink\";
";
echo "}
document.onkeyup = keyControl;
//-->\n </script>\r\n";
echo "<title>$browsertitle</title>";
echo "</head>";
echo "<body style=\"background-color:$bgcolor\" onmouseover=\"hideData()\">";//<span class=\"browser\">
echo "<div align=\"center\" class=\"controlTable\">";
//echo "<form name=\"ctrl\" action=\"\">";
echo "<table onmouseover=\"hideData()\" style=\"vertical-align:middle;\" align=\"center\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\"><tr>";
echo "<td><input class=\"slidebrowse\" type=\"button\" value=\"$slidesString\" name=\"B1\" onClick=\"slides();\"/></td>";
if($allowZip)
echo "<td><input class=\"downloadLink\" type=\"button\" value=\"$downloadButton\" onClick=\"downloadExec();\"/></td>";
echo "</tr></table>";
echo "<table onmouseover=\"hideData()\" style=\"vertical-align:middle;\" align=\"center\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\"><tr>";
echo "<td><a class=\"goLink\" ";
if($offset<=0)
echo "style=\"color:#aaa; text-decoration:none;\" ";
else
echo "href=\"$priorPageLink\"";
echo " ><$priorPageString</a></td>";
$startxi=$offset%$maxperpage;
$countxi=1;
if($startxi!=0){
echo "<td><a class=\"goLink\" ";
echo "href=\"$SCRNAME?$GD_WORKAROUND$sep"."0\"";
echo " >$countxi</td>";
$countxi++;
}
for($xi=$startxi;$xi<sizeof($filter_files);$xi+=$maxperpage){
//if($xi%sizeof($filter_files)==$startxi)
echo "<td><a class=\"goLink\" ";
if($xi==$offset)
echo "style=\"color:#a00; font-weight:bold; text-decoration:none;\" ";
else
echo "href=\"$SCRNAME?$GD_WORKAROUND$sep".strval($xi)."\"";
echo " >$countxi</td>";
$countxi++;
}
echo "<td><a class=\"goLink\" ";
if($offset+$maxperpage>=sizeof($filter_files))
echo "style=\"color:#aaa; text-decoration:none;\" ";
else
echo "href=\"$nextPageLink\"";
echo " >$nextPageString></a></td>";
echo "</tr></table></div>";//</tr></table></form></div>
echo "<div align=\"center\"><center>\n";
echo "<table onmouseover=\"hideData()\" width=\"100%\"; border=\"0\" cellpadding=\"0\" cellspacing=\"4\" style=\"table-layout:fixed; height:100;\">\r\n";//
$newline=false;
$firstTime=true;
for($i=$offset;($i<sizeof($filter_files)&&$i<$offset+$maxperpage);$i++){
if((array_key_exists($i,$picTexts))&&($picTexts[$i])&&(trim($picTexts[$i])!=""))
$textStyle="border-bottom-style:dashed;";
else
$textStyle="";
if(($i-$offset) % $imgsperline==0) //$scrwidth - ($realimgwidth*i % $scrwidth) - $imgwidth<0)
$newline=true;
if($newline==true){
if(!$firstTime){
echo "</tr>";
$firstTime=false;
}
echo "<tr onmouseover=\"hideData()\" style=\"text-align:center; vertical-align:middle\">";
$newline=false;
}
if($GD_WORKAROUND=="oldGD"){
$winfo=getimagesize("$filter_files[$i]");
$wwidth=$imgwidth;
$wheight=$winfo[1]*($imgwidth/$winfo[0]);
//workaround for old PHP version (GD < 1.8), no jpeg abilities
echo "<td class=\"browsetd\" width=\"".strval(100/$imgsperline)."%\"><div style=\"$textStyle\" class=\"tdpic\"><a href=\"$SCRNAME?$GD_WORKAROUND$sep"."slides$sep".$i."\"><img border=\"0\" alt=\"".$filter_files[$i]."\" src=\"".$filter_files[$i]."\" onmouseover=\"showData($i,this)\" width=\"100%\"></a></div></td>";//was: width=\"$wwidth\" height=\"$wheight\"
}
else
echo "<td class=\"browsetd\" width=\"".strval(100/$imgsperline)."%\"><div style=\"$textStyle\" class=\"tdpic\"><a href=\"$SCRNAME?$GD_WORKAROUND$sep"."slides$sep".$i."\"><img class=\"tdpic\" border=\"0\" alt=\"".$filter_files[$i]."\" src=\"".$SCRNAME."?$GD_WORKAROUND$sep"."image".$sep.$filter_files[$i].$sep.$imgwidth."\" onmouseover=\"showData($i,this)\" width=\"100%\" ></a></div></td>";
}
$fillup=$imgsperline-(sizeof($filter_files)-$offset);
for($i=$fillup;$i>0;$i--)
echo "<td class=\"browsetd\" width=\"".strval(100/$imgsperline)."%\"></td>";
echo "</tr>\n</table></center></div>
<table><tr><td onmouseover=\"dontHide=true\" onmouseout=\"dontHide=false\" class=\"currpic\" style=\"border-top-style:none; z-index:99; visibility:hidden; position:absolute\" id=\"infotext\">
</td></tr></table>";
echo "$aftertext</body>";
echo "</html>";
die;