5, December 2008

Need help for On the fly zip tutorial - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Miscellaneous scripts or snippets (Moderator: Olaf)
Topic: Need help for On the fly zip tutorial
« previous next »
Pages: 1 [2] Print

Author Topic: Need help for On the fly zip tutorial  (Read 2062 times)
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6486
39748 credits
Members referred : 374


It's time to use PHP5!


« Reply #20 on: Nov 13, 2007, 12:07:12 PM »

you need to create a second array for the files and use it together with this if statement:

if (is_file($directory.$file) && !in_array($excl_files)) {


Last blog : Just a better Internet portal provided by Google
Atari ST fan
*
Posts: 7
42 credits
Members referred : 0


« Reply #21 on: Nov 13, 2007, 01:18:13 PM »

Could you give me a piece of code or something.. more exactly ?
I'm sorry but I'm new in PHP and I really need this.

Regards,
Alex
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6486
39748 credits
Members referred : 374


It's time to use PHP5!


« Reply #22 on: Nov 13, 2007, 01:48:42 PM »

Could you give me a piece of code or something.. more exactly ?
I'm sorry but I'm new in PHP and I really need this.

Regards,
Alex

just replace the old row with the new one (it's about a tiny snippet) Wink


Last blog : Just a better Internet portal provided by Google
Atari ST fan
*
Posts: 7
42 credits
Members referred : 0


« Reply #23 on: Nov 13, 2007, 02:16:10 PM »

Please, look at my code.. what I'm wrong ?
Code:
<?php
$excl_files 
= array("index.php",".htaccess");

include_once(
"CreateZipFile.inc.php"); // zip class
class createDirZip extends createZip {
  function 
get_files_from_folder($directory$put_into) {
    if (
$handle opendir($directory)) {
      while (
false !== ($file readdir($handle))) {
     if (
is_file($directory.$file) && !in_array($excl_files)) {
          
$fileContents file_get_contents($directory.$file);
          
$this->addFile($fileContents$put_into.$file);
        } elseif (
$file != '.' and $file != '..' and is_dir($directory.$file)) {
          
$this->addDirectory($put_into.$file.'/');
          
$this->get_files_from_folder($directory.$file.'/'$put_into.$file.'/');
        }
      }
    }
    
closedir($handle);
  }
}


$createZip = new createDirZip;
$createZip->addDirectory('folder/');
$createZip->get_files_from_folder('folder/''folder/');

$fileName 'archive.zip';
$fd fopen ($fileName'wb');
$out fwrite ($fd$createZip->getZippedfile());
fclose ($fd);

$createZip->forceDownload($fileName);
@
unlink($fileName);

?>

Regards,
Alex
« Last Edit: Nov 13, 2007, 02:49:33 PM by alexro »
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6486
39748 credits
Members referred : 374


It's time to use PHP5!


« Reply #24 on: Nov 13, 2007, 03:09:19 PM »

looks good, does it work without the filter?


Last blog : Just a better Internet portal provided by Google
Atari ST fan
*
Posts: 7
42 credits
Members referred : 0


« Reply #25 on: Nov 13, 2007, 03:18:23 PM »

Yes, perfectly.

Errors:
Warning: Wrong parameter count for in_array() in /home/test.php on line 9

Warning: Cannot modify header information - headers already sent by (output started at /home/test.php:9) in /home/CreateZipFile.inc.php on line 182

Regards,
Alex
« Last Edit: Nov 13, 2007, 03:22:52 PM by alexro »
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6486
39748 credits
Members referred : 374


It's time to use PHP5!


« Reply #26 on: Nov 13, 2007, 03:20:24 PM »

there was an error

must be

if (is_file($directory.$file) && !in_array($file, $excl_files)) {


Last blog : Just a better Internet portal provided by Google
Atari ST fan
*
Posts: 7
42 credits
Members referred : 0


« Reply #27 on: Nov 13, 2007, 03:24:15 PM »

Now it gives me:

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/test.php on line 9
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6486
39748 credits
Members referred : 374


It's time to use PHP5!


« Reply #28 on: Nov 13, 2007, 03:54:20 PM »

the second value must be an array...


Last blog : Just a better Internet portal provided by Google
Atari ST fan
*
Posts: 7
42 credits
Members referred : 0


« Reply #29 on: Nov 13, 2007, 05:01:30 PM »

I solved the problem, thank you.

Regards,
Alex
« Last Edit: Nov 13, 2007, 08:35:40 PM by alexro »
I crack Photoshop!
*
Posts: 3
18 credits
Members referred : 0


« Reply #30 on: Nov 24, 2007, 07:33:01 PM »

I'm not sure what to do with the classes file... im getting this error:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/public_html/tmp/createzip.php on line 11

Code:
<?php

/**
* Class to dynamically create a zip file (archive)
*
* @author Rochak Chauhan
*/

class createZip {

public $compressedData = array();
public $centralDirectory = array(); // central directory
public $endOfCentralDirectory "\x50\x4b\x05\x06\x00\x00\x00\x00"//end of Central directory record
public $oldOffset 0;

/**
* Function to create the directory where the file(s) will be unzipped
*
* @param $directoryName string
*
*/

public function addDirectory($directoryName) {
$directoryName str_replace("\\""/"$directoryName);

$feedArrayRow "\x50\x4b\x03\x04";
$feedArrayRow .= "\x0a\x00";
$feedArrayRow .= "\x00\x00";
$feedArrayRow .= "\x00\x00";
$feedArrayRow .= "\x00\x00\x00\x00";

$feedArrayRow .= pack("V",0);
$feedArrayRow .= pack("V",0);
$feedArrayRow .= pack("V",0);
$feedArrayRow .= pack("v"strlen($directoryName) );
$feedArrayRow .= pack("v");
$feedArrayRow .= $directoryName;

$feedArrayRow .= pack("V",0);
$feedArrayRow .= pack("V",0);
$feedArrayRow .= pack("V",0);

$this -> compressedData[] = $feedArrayRow;

$newOffset strlen(implode(""$this->compressedData));

$addCentralRecord "\x50\x4b\x01\x02";
$addCentralRecord .="\x00\x00";
$addCentralRecord .="\x0a\x00";
$addCentralRecord .="\x00\x00";
$addCentralRecord .="\x00\x00";
$addCentralRecord .="\x00\x00\x00\x00";
$addCentralRecord .= pack("V",0);
$addCentralRecord .= pack("V",0);
$addCentralRecord .= pack("V",0);
$addCentralRecord .= pack("v"strlen($directoryName) );
$addCentralRecord .= pack("v");
$addCentralRecord .= pack("v");
$addCentralRecord .= pack("v");
$addCentralRecord .= pack("v");
$ext "\x00\x00\x10\x00";
$ext "\xff\xff\xff\xff";
$addCentralRecord .= pack("V"16 );

$addCentralRecord .= pack("V"$this -> oldOffset );
$this -> oldOffset $newOffset;

$addCentralRecord .= $directoryName;

$this -> centralDirectory[] = $addCentralRecord;
}

/**
* Function to add file(s) to the specified directory in the archive
*
* @param $directoryName string
*
*/

public function addFile($data$directoryName) {

$directoryName str_replace("\\""/"$directoryName);

$feedArrayRow "\x50\x4b\x03\x04";
$feedArrayRow .= "\x14\x00";
$feedArrayRow .= "\x00\x00";
$feedArrayRow .= "\x08\x00";
$feedArrayRow .= "\x00\x00\x00\x00";

$uncompressedLength strlen($data);
$compression crc32($data);
$gzCompressedData gzcompress($data);
$gzCompressedData substrsubstr($gzCompressedData0strlen($gzCompressedData) - 4), 2);
$compressedLength strlen($gzCompressedData);
$feedArrayRow .= pack("V",$compression);
$feedArrayRow .= pack("V",$compressedLength);
$feedArrayRow .= pack("V",$uncompressedLength);
$feedArrayRow .= pack("v"strlen($directoryName) );
$feedArrayRow .= pack("v");
$feedArrayRow .= $directoryName;

$feedArrayRow .= $gzCompressedData;

$feedArrayRow .= pack("V",$compression);
$feedArrayRow .= pack("V",$compressedLength);
$feedArrayRow .= pack("V",$uncompressedLength);

$this -> compressedData[] = $feedArrayRow;

$newOffset strlen(implode(""$this->compressedData));

$addCentralRecord "\x50\x4b\x01\x02";
$addCentralRecord .="\x00\x00";
$addCentralRecord .="\x14\x00";
$addCentralRecord .="\x00\x00";
$addCentralRecord .="\x08\x00";
$addCentralRecord .="\x00\x00\x00\x00";
$addCentralRecord .= pack("V",$compression);
$addCentralRecord .= pack("V",$compressedLength);
$addCentralRecord .= pack("V",$uncompressedLength);
$addCentralRecord .= pack("v"strlen($directoryName) );
$addCentralRecord .= pack("v");
$addCentralRecord .= pack("v");
$addCentralRecord .= pack("v");
$addCentralRecord .= pack("v");
$addCentralRecord .= pack("V"32 );

$addCentralRecord .= pack("V"$this -> oldOffset );
$this -> oldOffset $newOffset;

$addCentralRecord .= $directoryName;

$this -> centralDirectory[] = $addCentralRecord;
}

/**
* Fucntion to return the zip file
*
* @return zipfile (archive)
*/

public function getZippedfile() {

$data implode(""$this -> compressedData);
$controlDirectory implode(""$this -> centralDirectory);

return
$data.
$controlDirectory.
$this -> endOfCentralDirectory.
pack("v"sizeof($this -> centralDirectory)).
pack("v"sizeof($this -> centralDirectory)).
pack("V"strlen($controlDirectory)).
pack("V"strlen($data)).
"\x00\x00";
}

/**
*
* Function to force the download of the archive as soon as it is created
*
* @param archiveName string - name of the created archive file
*/

public function forceDownload($archiveName) {
$headerInfo '';

if(
ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression''Off');
}

// Security checks
if( $archiveName == "" ) {
echo 
"<html><title>Public Photo Directory - Download </title><body><BR><B>ERROR:</B> The download file was NOT SPECIFIED.</body></html>";
exit;
}
elseif ( ! 
file_exists$archiveName ) ) {
echo 
"<html><title>Public Photo Directory - Download </title><body><BR><B>ERROR:</B> File not found.</body></html>";
exit;
}

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=".basename($archiveName).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($archiveName));
readfile("$archiveName");

}

}
?>

Is that the right code?

and I'm calling this one:

Code:
<?php
include_once("createzip.php"); // zip class
class createDirZip extends createZip {
function 
get_files_from_folder($directory$put_into) {
if (
$handle opendir($directory)) {
while (
false !== ($file readdir($handle))) {
if (
is_file($directory.$file) && !in_array($excl_files)) {
$fileContents file_get_contents($directory.$file);
$this->addFile($fileContents$put_into.$file);
} elseif (
$file != '.' and $file != '..' and is_dir($directory.$file)) {
$this->addDirectory($put_into.$file.'/');
$this->get_files_from_folder($directory.$file.'/'$put_into.$file.'/');
}
}
}
closedir($handle);
}
}


$createZip = new createDirZip;
$createZip->addDirectory('cretest/');
$createZip->get_files_from_folder('home/tyscodsu/public_html/cretest/''cretest/');

$fileName 'archive.zip';
$fd fopen ($fileName'wb');
$out fwrite ($fd$createZip->getZippedfile());
fclose ($fd);

$createZip->forceDownload($fileName);
@
unlink($fileName);

?>
« Last Edit: Nov 24, 2007, 07:35:34 PM by GPM »
I crack Photoshop!
*
Posts: 3
18 credits
Members referred : 0


« Reply #31 on: Nov 25, 2007, 02:24:07 AM »

Ok I don't know much php but I think its this:

Code:
class createZip {
public $compressedData = array();
public $centralDirectory = array(); // central directory
public $endOfCentralDirectory = "\x50\x4b\x05\x06\x00\x00\x00\x00"; //end of Central directory record
public $oldOffset = 0;

It doesn't have a the (  ) part like this one does:

Code:
public function addDirectory($directoryName) {
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6486
39748 credits
Members referred : 374


It's time to use PHP5!


« Reply #32 on: Nov 25, 2007, 11:09:29 AM »

you need PHP5 to run the script


Last blog : Just a better Internet portal provided by Google
I crack Photoshop!
*
Posts: 3
18 credits
Members referred : 0


« Reply #33 on: Nov 25, 2007, 08:33:22 PM »

you need PHP5 to run the script

oh, well that sucks... is it easy to modify to work with php 4.3.9?
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6486
39748 credits
Members referred : 374


It's time to use PHP5!


« Reply #34 on: Nov 25, 2007, 09:25:27 PM »

you need PHP5 to run the script

oh, well that sucks... is it easy to modify to work with php 4.3.9?

you need to remove the "public , private" keywords and maybe you need to replace some php5 only functions...(better is a modern php5 enabled webserver, php4 will stop the development at the end of this year)


Last blog : Just a better Internet portal provided by Google
Just another rainy day
*
Posts: 1
6 credits
Members referred : 0


« Reply #35 on: Nov 30, 2007, 05:23:10 AM »

hello,

i need step by step instructions for this (noob) - can anyone help?

 - i downloaded the files from http://olederer.users.phpclasses.org/browse/package/2322.html Visit through proxy
 - two of the files didnt have file name extensions, i am guesing they are php so i added .php to them. 

So my questions are:

Do you upload all three files (CreateZipFile.php, CreateZipFileMac.zip.php, exampleScript.php) to any location on your server?

And then what do you do?

Thank You!

EDIT:  By the way, i just have a collection of individual files that i want the user to be able to select from (checkboxes?) which would then be added to one zip file for them to download. 

« Last Edit: Nov 30, 2007, 05:32:14 AM by rw1 »
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7291
Tags : only the fly zipping Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: 1 [2] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Miscellaneous scripts or snippets (Moderator: Olaf)
Topic: Need help for On the fly zip tutorial
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Dec 05, 2008, 03:51:55 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 37.995
Total Topics: 7.685
Total Members: 4.467
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: jschless81

30 Guests, 5 Users online :

10 users online today: