Creating zip files

Σε αυτή την περιοχή μπορείτε να βρείτε ή να αναζητήσετε πληροφορίες σχετικές με την PHP

Συντονιστές: WebDev Moderators, Super-Moderators, PHP Moderators

Απάντηση
AlexanderTheGr
Δημοσιεύσεις: 153
Εγγραφή: 11 Ιούλ 2003 04:22
Επικοινωνία:

Creating zip files

Δημοσίευση από AlexanderTheGr » 18 Οκτ 2003 07:22

Xrisimopoio mia class pou pira apo ton phpMyAdmin gia na ftiaxno zip files

Sas paratheto tin class
class zipfile
{
/**
* Array to store compressed data
*
* @var array $datasec
*/
var $datasec = array();

/**
* Central directory
*
* @var array $ctrl_dir
*/
var $ctrl_dir = array();

/**
* End of central directory record
*
* @var string $eof_ctrl_dir
*/
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";

/**
* 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) {
$timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);

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 addFile($data, $name, $time = 0)
{
$name = str_replace('\\', '/', $name);

$dtime = dechex($this->unix2DosTime($time));
$hexdtime = '\x' . $dtime[6] . $dtime[7]
. '\x' . $dtime[4] . $dtime[5]
. '\x' . $dtime[2] . $dtime[3]
. '\x' . $dtime[0] . $dtime[1];
eval('$hexdtime = "' . $hexdtime . '";');

$fr = "\x50\x4b\x03\x04";
$fr .= "\x14\x00"; // ver needed to extract
$fr .= "\x00\x00"; // gen purpose bit flag
$fr .= "\x08\x00"; // compression method
$fr .= $hexdtime; // last mod time and date

// "local file header" segment
$unc_len = strlen($data);
$crc = crc32($data);
$zdata = gzcompress($data);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug
$c_len = strlen($zdata);
$fr .= pack('V', $crc); // crc32
$fr .= pack('V', $c_len); // compressed filesize
$fr .= pack('V', $unc_len); // uncompressed filesize
$fr .= pack('v', strlen($name)); // length of filename
$fr .= pack('v', 0); // extra field length
$fr .= $name;

// "file data" segment
$fr .= $zdata;

// "data descriptor" segment (optional but necessary if archive is not
// served as file)
$fr .= pack('V', $crc); // crc32
$fr .= pack('V', $c_len); // compressed filesize
$fr .= pack('V', $unc_len); // uncompressed filesize

// add this entry to array
$this -> datasec[] = $fr;
$new_offset = strlen(implode('', $this->datasec));

// now add to central directory record
$cdrec = "\x50\x4b\x01\x02";
$cdrec .= "\x00\x00"; // version made by
$cdrec .= "\x14\x00"; // version needed to extract
$cdrec .= "\x00\x00"; // gen purpose bit flag
$cdrec .= "\x08\x00"; // compression method
$cdrec .= $hexdtime; // last mod time & date
$cdrec .= pack('V', $crc); // crc32
$cdrec .= pack('V', $c_len); // compressed filesize
$cdrec .= pack('V', $unc_len); // uncompressed filesize
$cdrec .= pack('v', strlen($name) ); // length of filename
$cdrec .= pack('v', 0 ); // extra field length
$cdrec .= pack('v', 0 ); // file comment length
$cdrec .= pack('v', 0 ); // disk number start
$cdrec .= pack('v', 0 ); // internal file attributes
$cdrec .= pack('V', 32 ); // external file attributes - 'archive' bit set

$cdrec .= pack('V', $this -> old_offset ); // relative offset of local header
$this -> old_offset = $new_offset;

$cdrec .= $name;

// optional extra field, file comment goes here
// save to central directory
$this -> ctrl_dir[] = $cdrec;
} // end of the 'addFile()' method


/**
* Dumps out file
*
* @return string the zipped file
*
* @access public
*/
function file()
{
$data = implode('', $this -> datasec);
$ctrldir = implode('', $this -> ctrl_dir);

return
$data .
$ctrldir .
$this -> eof_ctrl_dir .
pack('v', sizeof($this -> ctrl_dir)) . // total # of entries "on this disk"
pack('v', sizeof($this -> ctrl_dir)) . // total # of entries overall
pack('V', strlen($ctrldir)) . // size of central dir
pack('V', strlen($data)) . // offset to start of central dir
"\x00\x00"; // .zip file comment length
} // end of the 'file()' method

} // end of the 'zipfile' class
Mexri kapoio seimio i class leitourgei apsoga

Omos an prospathiso na zip zip ena sxetika megalo ogko arxeion tote i diadikasi apotixanei. Mipos exete kamia idea pos mporei na diorthothei to problima ayto?

Άβαταρ μέλους
Cha0s
SysAdmin
Δημοσιεύσεις: 10242
Εγγραφή: 28 Ιούλ 2001 03:00

Creating zip files

Δημοσίευση από Cha0s » 18 Οκτ 2003 09:00

Otan Les Apotigxanei ?

Ti krivos simvenei ?
Ti sou bgazei ?

AlexanderTheGr
Δημοσιεύσεις: 153
Εγγραφή: 11 Ιούλ 2003 04:22
Επικοινωνία:

Creating zip files

Δημοσίευση από AlexanderTheGr » 18 Οκτ 2003 10:12

Basika prepei na paizei me to time limit stin entoli
"$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);"

fisiko einai an milame gia kamposa MBs

to thema einai oti ayto to error mou to petaei otan kano test to PC mou kai to kako einai oti o host tou site den me enireroni gia errors akoma kai an bazo tin entoli "error_reporting(E_ALL)"

Άβαταρ μέλους
Rapid-eraser
WebDev Moderator
Δημοσιεύσεις: 6851
Εγγραφή: 05 Απρ 2003 17:50
Τοποθεσία: Πειραιάς
Επικοινωνία:

Creating zip files

Δημοσίευση από Rapid-eraser » 18 Οκτ 2003 11:19

n texviki packing opos legete pou pataei stov algori8mo tou zip
pou ektelei to myadmin dev eivai n kaliteri divati kai fisika apotigxvavei
otav exeis va simpieseis megalo mege8os arxeiou ka8os de prolabevei
va teliosei to script mesa sta plaisia tou xrovouv twv 30sec idios
otav exei va kavei me binnary arxeia pou exouv poli pragma va kavouv
prosses. 8a mou pite ma kala pos to kavei me tis baseis egw exo
kavei zip 50mb basi kai mou tnv ebgale ok !!!
vai ovtos etsi eivai giati n basi eivai text kai oxi bannary !!!

http://www.zend.com/zend/spotlight/crea ... files1.php

diabaste tov parapavo odigo kai 8a katalabete ti evoo.

to problima eivai sto oti avagkazese va kaveis transpose merikous
xaraktires pou eivai arketa epipovi diadikasia.

av zitate kati pio sigouro grigoro kai divato tote xrisimopiiste
bzip2 n zlib pou eivai arketa pio grigores (afou eivai grameves se core)
kai fisika mporouv va kavouv kaliteri douleia apo to aplo packing pou 8a
kavei kapoios me tnv texviki tou myadmin.

fisika me eva aplo winzip8 kai pavo kai winrar 8a mporeite va kavete
uncompress sta arxeia pou dimiourgouvte me tis parapavo texvikes
pou fisika eivai pio olokliromeves.
Cu, Rapid-eraser, Tα αγαθά copies κτώνται.
Love is like oxygen, You get too much you get too high
Not enough and you're gonna die, Love gets you high

Άβαταρ μέλους
Cha0s
SysAdmin
Δημοσιεύσεις: 10242
Εγγραφή: 28 Ιούλ 2001 03:00

Creating zip files

Δημοσίευση από Cha0s » 18 Οκτ 2003 11:20

dokimase stin arxi tou script na baleis tin eksis function>

Κώδικας: Επιλογή όλων

@set_time_limit &#40;0&#41;; 
An to script pernei pano apo 30seconds (ayto einai to default mporei ston server na to exoun rithmisei se allo xroniko orio) tote to script stamataei kai petaei error...

Me tin parapano function kaneis to script na trexei ep aoriston mexri na teleiosei...(efoson i PHP ston server einai rithmismeni etsi oste na afinei tin xrisi aytis tin function...)

Allios.... paketo :P (an telika to error einai gia ton xrono...)

AlexanderTheGr
Δημοσιεύσεις: 153
Εγγραφή: 11 Ιούλ 2003 04:22
Επικοινωνία:

Creating zip files

Δημοσίευση από AlexanderTheGr » 18 Οκτ 2003 14:11

dokimase stin arxi tou script na baleis tin eksis function>

κώδικας:
@set_time_limit (0);


An to script pernei pano apo 30seconds (ayto einai to default mporei ston server na to exoun rithmisei se allo xroniko orio) tote to script stamataei kai petaei error...

Me tin parapano function kaneis to script na trexei ep aoriston mexri na teleiosei...(efoson i PHP ston server einai rithmismeni etsi oste na afinei tin xrisi aytis tin function...)

Allios.... paketo (an telika to error einai gia ton xrono...)
ti perimenes? Na sou epetrepe na kaneis xrisi to set_time_limit? :P Edo oute ta errors mou bgazei gia na sigoureyto oti pragmati prokeite gia to time_limit

Άβαταρ μέλους
Cha0s
SysAdmin
Δημοσιεύσεις: 10242
Εγγραφή: 28 Ιούλ 2001 03:00

Creating zip files

Δημοσίευση από Cha0s » 18 Οκτ 2003 14:19

Basika toulaxiston gia ta errors mporeis na to apaitiseis na ta exoun on...

Gia to time limit exoun to dikaioma na to exoun kleidomeno (profanos tha trexei se safe mode i PHP tous) gia tin prostasia kai omali leitourgia tou server...

Skepsou na exoun 100 accounts kai oi 60 users na pane na kanoun zip me ayto ton tropo gia arxeia dekadon MB... paei to sistima tha gonatisei :P

Άβαταρ μέλους
iNDEFiX
Honorary Member
Δημοσιεύσεις: 2569
Εγγραφή: 20 Δεκ 2002 00:48
Τοποθεσία: κλειστή λόγω έργων
Επικοινωνία:

Creating zip files

Δημοσίευση από iNDEFiX » 18 Οκτ 2003 16:45

Gia ti pragma to xreiazesai akrivos? Mia aplh kai kalh lysh einai h ekshs:

system("zip file.zip source");

kai

system("zip file.zip -r directory");

Άβαταρ μέλους
Cha0s
SysAdmin
Δημοσιεύσεις: 10242
Εγγραφή: 28 Ιούλ 2001 03:00

Creating zip files

Δημοσίευση από Cha0s » 18 Οκτ 2003 17:14

ayto omos eiani mono gia linux server...

an exei windows server ti tha kanei ? :P

Απάντηση

Επιστροφή στο “PHP Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 1 επισκέπτης