note 49464 added to function.gzencode
| From: | bunioxxx at poczta dot onet dot pl | Date: | Fri, 28 Jan 2005 23:18:24 +0000 |
| Subject: | note 49464 added to function.gzencode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84138@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.gzencode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49464
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49464&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49464&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49464&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49464&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49464&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49464&report=yes
Search -- http://master.php.net/manage/user-notes.php