Hi,
if you have the RAW CONTENT OF THE ZIP FILE IN A STRING ONLY and you can't create files on your server (because of the SAFE MODE) to be able to create a file which you can then pass to zip_open(), you'll be having hard times getting the uncompressed content of your ZIP data.
This may help:
I've written simple ZIP decompression function for decompressing the first file from the archive stored in a string (no matter what file it is). It's just about parsing a local file header of the first file, getting raw compressed data of that file and decompression of that data (usually, data in ZIP files are compressed by 'DEFLATE' method, so we'll just decompress it by gzinflate() function then).
<?php
function decompress_first_file_from_zip($ZIPContentStr){
if(strlen($ZIPContentStr)<102){
printf("error: input data too short<br />\n");
return '';
}
$CompressedSize=binstrtonum(substr($ZIPContentStr,18,4));
$UncompressedSize=binstrtonum(substr($ZIPContentStr,22,4));
$FileNameLen=binstrtonum(substr($ZIPContentStr,26,2));
$ExtraFieldLen=binstrtonum(substr($ZIPContentStr,28,2));
$Offs=30+$FileNameLen+$ExtraFieldLen;
$ZIPData=substr($ZIPContentStr,$Offs,$CompressedSize);
$Data=gzinflate($ZIPData);
if(strlen($Data)!=$UncompressedSize){
printf("error: uncompressed data have wrong size<br />\n");
return '';
}
else return $Data;
}
function binstrtonum($Str){
$Num=0;
for($TC1=strlen($Str)-1;$TC1>=0;$TC1--){ $Num<<=8; $Num|=ord($Str[$TC1]); }
return $Num;
}
?>
ENJOY!!!
wdim