function dosdate_return($dosdate) { $dosdate = decbin(ascii2dec($dosdate)); //looks nasty, but hey, it works ;) $dosdate = str_pad($dosdate, 16, "0", STR_PAD_LEFT); // retreiving the needed data... 5-4-7 was the format // *** Warning! *** Waarschuwing! *** Achtung! *** // I don't know if this works on little endian machines the way it works on big-endian ones // So let's hope for the best $return['year'] = substr($dosdate, 0, 7); $return['month'] = substr($dosdate, 7, 4); $return['day'] = substr($dosdate, 11, 5); unset($dosdate); // now processing the info to the right format $return['day'] = bindec($return['day']); $return['month'] = bindec($return['month']); $return['year'] = bindec($return['year']) + 1980; return $return; }
public function zl_index_file($file) { $fp = @fopen($file, "rb"); // ok, as we don't know what the exact position of everything is, we'll have to "guess" using the default sizes //and set values in the zipfile. Basicly this means I have to go through the entire file, could take some time. //Let's see if I can create an algorithm powerful enough. if (!$fp) { die("File empty"); } $continue = 1; $file_count = 0; while ($continue) { $content = fread($fp, 30); $id = substr($content, 0, 4); if ($id == "PK") { // the method used is quite simple, load a file in the memory, and walk through several parts of it using substr // As the PKZip format uses mostly fixed sizes for information, this isn't too hard to implement // First I want everything tested, before I start giving this function a nice place in the class $temp[$file_count]['file-size'] = ascii2dec(substr($content, 18, 4)); $temp[$file_count]['filename-size'] = ascii2dec(substr($content, 26, 2)); $temp[$file_count]['compression-type'] = ascii2dec(substr($content, 8, 2)); $temp[$file_count]['crc'] = ascii2dec(substr($content, 14, 4)); $temp[$file_count]['dostime'] = dostime_return(substr($content, 10, 2)); $temp[$file_count]['dosdate'] = dosdate_return(substr($content, 12, 2)); $temp[$file_count]['filename'] = fread($fp, $temp[$file_count]['filename-size']); // As the Zip format does not include Content type headers, I'll create a nice little array with // extension/content type, and a small function to retreive it $temp[$file_count]['file-type'] = ext2cth($temp[$file_count]['filename']); $temp[$file_count]['content'] = fread($fp, $temp[$file_count]['file-size']); if ($temp[$file_count]['compression-type'] != 0 and $temp[$file_count]['compression-type'] != 8 and $temp[$file_count]['compression-type'] != 12) { $temp[$file_count]['lasterror'] = "Compression type not supported"; } else { if ($temp[$file_count]['compression-type'] == 8) { $temp[$file_count]['content'] = gzinflate($temp[$file_count]['content']); } elseif ($temp[$file_count]['compression-type'] == 12) { $temp[$file_count]['content'] = bzdecompress($temp[$file_count]['content']); } $verify = crc32($temp[$file_count]['content']); if ($verify != $temp[$file_count]['crc']) { $temp[$file_count]['lasterror'] = "CRC did not match, possibly this zipfile is damaged"; } } $file_count++; } else { $continue = 0; } } fclose($fp); unset($fp, $content, $file_count); return $temp; }