note 49464 deleted from function.gzencode by nlopess
| From: | nlopess@php.net | Date: | Fri, 28 Jan 2005 23:29:19 +0000 |
| Subject: | note 49464 deleted from function.gzencode by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-84139@lists.php.net to get a copy of this message | ||
Note Submitter: bunioxxx at poczta dot onet dot pl
Reason: useless
----
many of you reading notes on this page probably wondered how to send many files through a single
file declaration... here's a script which converts an table into a zip file pkzip compatible
(with no dates; but who actually cares about them?)... takes a table and returns a string which only
needs to be echoed after sending appropiate headers (>"Content-type: application/x-zip"
is mondatory of course)...
it will prove usefull with safemode mysql blobdata mass sending (you can send multiple files
without disk usage through a single zip pipeline)
function int2str($value,$len=2)
{
$strdata='';
$mask=255;
$order=1;
for($i=0; $i<$len; $i++, $order*=256)
$strdata.=chr(($value&($mask*$order))/$order);
return $strdata;
}
function zipme($dane)
{
$i=0; $pos=0; $moc=0;
foreach($dane as $zm => $val)
{
$local[$i]=int2str(0x04034b50,4);
$local[$i].=int2str(0);
$local[$i].=int2str(2);
$local[$i].=int2str(8);
// last mod file time 2 bytes
$local[$i].=int2str(0);
// last mod file date 2 bytes
$local[$i].=int2str(0);
$zipdata=gzdeflate($val,9);
$local[$i].=int2str(crc32($val),4);
$local[$i].=int2str(strlen($val)-1,4);
$local[$i].=int2str(strlen($zipdata),4);
$local[$i].=int2str(strlen($zm));
$local[$i].=int2str(0);
$local[$i].=$zm;
$local[$i].=$zipdata;
$central[$i]=int2str(0x02014b50,4);
$central[$i].=int2str(0);
$central[$i].=int2str(0);
$central[$i].=int2str(2);
$central[$i].=int2str(8);
// last mod file time 2 bytes
$central[$i].=int2str(0);
// last mod file date 2 bytes
$central[$i].=int2str(0);
$central[$i].=int2str(crc32($val),4);
$central[$i].=int2str(strlen($zipdata),4);
$central[$i].=int2str(strlen($val)-1,4);
$central[$i].=int2str(strlen($zm));
$central[$i].=int2str(0);
$central[$i].=int2str(0);
$central[$i].=int2str(0);
$central[$i].=int2str(0);
$central[$i].=int2str(0,4);
$central[$i].=int2str($pos,4);
$central[$i].=$zm;
$pos+=strlen($local[$i]);
$i++;
$moc+=strlen($central[$i]);
}
$output='';
for($j=0; $j<$i; $j++) $output.=$local[$j];
for($j=0; $j<$i; $j++) $output.=$central[$j];
$output.=int2str(0x05054b50,4);
$output.=int2str(0);
$output.=int2str(0x06054b50,4);
$output.=int2str(0);
$output.=int2str(0);
$output.=int2str($i);
$output.=int2str($i);
$output.=int2str($moc,4);
$output.=int2str($pos,4);
$output.=int2str(0);
return $output;
}
have fun!
Bunio_FH