Potrzebuje do pliku ZIP generowanego przez php dodac pliki znajdujace sie na serwerze. Z phpMyAdmin wyciagnolem klase obslugujaca ZIPy...
zip.lib.php:
<?php /* $Id: zip.lib.php,v 1.7 2002/10/23 04:17:26 robbat2 Exp $ */ // vim: expandtab sw=4 ts=4 sts=4: /** * Zip file creation class. * Makes zip files. * * Based on : * * http://www.zend.com/codex.php?id=535&single=1 * By Eric Mueller <eric@themepark.com> * * http://www.zend.com/codex.php?id=470&single=1 * by Denis125 <webmaster@atlant.ru> * * a patch from Peter Listiak <mlady@users.sourceforge.net> for last modified * date and time of the compressed file * * Official ZIP file format: http://www.pkware.com/appnote.txt * * @access public */ class zipfile { /** * Array to store compressed data * * @var array $datasec */ /** * Central directory * * @var array $ctrl_dir */ /** * End of central directory record * * @var string $eof_ctrl_dir */ var $eof_ctrl_dir = \"x50x4bx05x06x00x00x00x00\"; /** * Last offset position * * @var integer $old_offset */ var $old_offset = 0; /** * Converts an Unix timestamp to a four byte DOS date and time format (date * in high two bytes, time in low two bytes allowing magnitude comparison). * * @param integer the current Unix timestamp * * @return integer the current date in a four byte DOS format * * @access private */ function unix2DosTime($unixtime = 0) { if ($timearray['year'] < 1980) { $timearray['year'] = 1980; $timearray['mon'] = 1; $timearray['mday'] = 1; $timearray['hours'] = 0; $timearray['minutes'] = 0; $timearray['seconds'] = 0; } // end if return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1); } // end of the 'unix2DosTime()' method /** * Adds \"file\" to archive * * @param string file contents * @param string name of the file in the archive (may contains the path) * @param integer the current timestamp * * @access public */ function add_file($data, $name) // adds \"file\" to archive // $data - file contents // $name - name of file in archive. Add path if your want { //$name = str_replace(\"\", \"/\", $name); $hexdtime = 'x' . $dtime[6] . $dtime[7] . 'x' . $dtime[4] . $dtime[5] . 'x' . $dtime[2] . $dtime[3] . 'x' . $dtime[0] . $dtime[1]; $fr = \"x50x4bx03x04\"; $fr .= \"x14x00\"; // ver needed to extract $fr .= \"x00x00\"; // gen purpose bit flag $fr .= \"x08x00\"; // compression method $fr .= $hexdtime; // last mod time and date $zdata = gzcompress($data); $fr .= $name; // end of \"local file header\" segment // \"file data\" segment $fr .= $zdata; // \"data descriptor\" segment (optional but necessary if archive is not served as file) // add this entry to array $this -> datasec[] = $fr; // now add to central directory record $cdrec = \"x50x4bx01x02\"; $cdrec .= \"x00x00\"; // version made by $cdrec .= \"x14x00\"; // version needed to extract $cdrec .= \"x00x00\"; // gen purpose bit flag $cdrec .= \"x08x00\"; // compression method $cdrec .= $hexdtime; // last mod time & date $this -> old_offset = $new_offset; $cdrec .= $name; // optional extra field, file comment goes here // save to central directory $this -> ctrl_dir[] = $cdrec; } /** * Dumps out file * * @return string the zipped file * * @access public */ { return $data . $ctrldir . $this -> eof_ctrl_dir . \"x00x00\"; // .zip file comment length } // end of the 'file()' method } // end of the 'zipfile' class ?>
Niestety potrafie jedynie zapisac do tego ZIPa pliki txt...
test.php:
<?php require('zip.lib.php'); $zipfile = new zipfile(); // add the binary data stored in the string 'filedata' $filedata = \"jakis text\"; $zipfile -> add_file($filedata, \"file.txt\"); // OR instead of doing that, you can write out the file to the loca disk like this
: $filename = \"output.zip\"; // then offer it to the user to download: ?> <a href=\"output.zip\">Click here to download the new zip file.</a>
i teraz pytanie:
Czy ktos potrafilby napisac mi jak mozna dodac do ZIPa pliki pdf?? Nie koniecznie za pomoca tej klasy... jesli ktos ma jakis inny gotowy skrypt i chcialby sie podzielic chetnie zobacze
