5, September 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 1853 times)
Chicken-run Manager
*
Posts: 9
58 credits
Members referred : 0


« on: Oct 26, 2007, 03:23:26 PM »

Hi,

I came across with your interesting tutorial about on the fly zipping of file & folder at http://www.web-development-blog.com/archives/tutorial-create-a-zip-file-from-folders-on-the-fly/#comment-45831 Visit through proxy

I am testing out the things but it not working please check out :-

http://www.ajayvibha.com/tutorial-test.php Visit through proxy

What I want to do is that I want take the manually take the backup of my root folder “public_html” using your script.

Can anyone help.

Regards,
Ajay
India
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Oct 26, 2007, 05:49:43 PM »

you have still this error

Parse error: syntax error, unexpected '.' in /home/ajayvibh/public_html/0-make-zip.php on line 11

no you have to change the code since WP has replaced all single quotes


Last blog : Is your website is down? Know before your visitors do!
Chicken-run Manager
*
Posts: 9
58 credits
Members referred : 0


« Reply #2 on: Oct 26, 2007, 07:52:04 PM »

Hi Olaf,

Please note that I am not using any word press (WP) at all .I am just trying to use your script on a regular website which is made manually .What I want to do take the backup of the folder using your scripts

I hope that you are getting me now. Also it is not clear whether there is need for any third party programe or some other php component /classes to use your " zip on the fly tutorial"

Any help will be help to many people indeed in using it different way.You already made such a wonderful scripts but it needs little bit more for the wise spread use.

Thanks & Regards,
Ajay Jain
<snipped /> (edit: place your links into the signature)
« Last Edit: Oct 26, 2007, 08:37:24 PM by Olaf »
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Oct 26, 2007, 08:39:45 PM »

I never said that you're using WP Cheesy
You need to replace the single quotes from my blog because wordpress replace regular single quotes with something else. If you use that code it will not work.

you need the class from here (my code is just an extension)
http://olederer.users.phpclasses.org/browse/package/2322.html Visit through proxy


Last blog : Is your website is down? Know before your visitors do!
Chicken-run Manager
*
Posts: 9
58 credits
Members referred : 0


« Reply #4 on: Oct 27, 2007, 04:18:47 AM »

I have downloaded the classed, changed the code, allocate full directory permission in tmp folder also also replay . & .. with some dummy name also but still it does not work.

You can check out http://www.ajayvibha.com/tutorial-test.php Visit through proxy .

Regards,
Ajay
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Oct 27, 2007, 08:55:51 AM »

post the code from the file here (the file with all the errors)


Last blog : Is your website is down? Know before your visitors do!
Chicken-run Manager
*
Posts: 9
58 credits
Members referred : 0


« Reply #6 on: Oct 27, 2007, 09:03:34 AM »

<?php

include_once("createZip.inc.php");

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)) {
          $fileContents = file_get_contents($directory.$file);
          $this->addFile($fileContents, $put_into.$file);
        } elseif ($file != ‘ajay’ and $file != ‘vibha’ 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(‘public_html/’);
$createZip->get_files_from_folder(‘public_html’, ‘public_html/’);

$fileName = ‘tmp/ajay.zip’;
$fd = fopen ($fileName, ‘wb’);
$out = fwrite ($fd, $createZip->getZippedfile());
fclose ($fd);

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

?>
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Oct 27, 2007, 10:34:24 AM »

replace the single quotes as I told before:

like
$createZip->addDirectory(‘public_html/’);

must be

$createZip->addDirectory('public_html/');

you need to do that for the whole snipped


Last blog : Is your website is down? Know before your visitors do!
Chicken-run Manager
*
Posts: 9
58 credits
Members referred : 0


« Reply #8 on: Oct 27, 2007, 08:26:54 PM »

Thanks for the tips.

Yes it has worked now, thanks a lot indeed I appreciate your help.

Two small queries :

1) Is it possible to skip some folder ? Because while making the directory zip there are some system / scripts folder which are to be skipped.

2) Is it necessary to have php5 support on the server ? Can it work on the php4 supported server

Regards,
Ajay
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: Oct 28, 2007, 10:22:08 AM »

Q1:
yes you can create an array and test each value like:

class createDirZip extends createZip {
	

	
public $exclude = array();

	
public function get_files_from_folder($directory$put_into) {
	
	
if (
$handle opendir($directory)) {
	
	
	
while (
false !== ($file readdir($handle))) {
	
	
	
	
if (
is_file($directory.$file)) { 
	
	
	
	
	
$fileContents file_get_contents($directory.$file);  
	
	
	
	
	
$this->addFile($fileContents$put_into.$file); 
	
	
	
	
} elseif (
$file != '.' and $file != '..' and is_dir($directory.$file) and !in_array($this->exclude)) {
	
	
	
	
	
$this->addDirectory($put_into.$file.'/');
	
	
	
	
	
$this->get_files_from_folder($directory.$file.'/'$put_into.$file.'/');
	
	
	
	
}
	
	
	
}
	
	
}
	
	
closedir($handle);
	
}
}

$createZip = new createDirZip;  
$createZip->exclude = array('some_dir''next_dir');


Q2:
yes you can just remove the keywords public, private ... from the methods and vars

« Last Edit: Oct 28, 2007, 10:25:36 AM by Olaf »


Last blog : Is your website is down? Know before your visitors do!
Chicken-run Manager
*
Posts: 9
58 credits
Members referred : 0


« Reply #10 on: Oct 29, 2007, 07:03:17 AM »

Hi Olaf,

After incorporating the suggestion it generates lot of errors.

I have put all the testing file , sources code and working demo at http://www.ajayvibha.com/olaf/test.php Visit through proxy

You can check out yourself for error details in test 2 ( http://www.ajayvibha.com/olaf/mzex.php Visit through proxy)

Thanks & Regards,
Ajay
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #11 on: Oct 29, 2007, 07:27:45 AM »

again please post the code from the file with problems


Last blog : Is your website is down? Know before your visitors do!
Chicken-run Manager
*
Posts: 9
58 credits
Members referred : 0


« Reply #12 on: Oct 29, 2007, 07:32:37 AM »

For providing all the working details and comprehensive informatiion I have put everything at http://www.ajayvibha.com/olaf/test.php Visit through proxy

But any waya required by you please find below the code :

==============

<?php
include_once("czf.php");

class createDirZip extends createZipFile {

public $exclude = array();   

public function get_files_from_folder($directory, $put_into) {
    if ($handle = opendir($directory)) {
      while (false !== ($file = readdir($handle))) {
        if (is_file($directory.$file)) {
          $fileContents = file_get_contents($directory.$file);
          $this->addFile($fileContents, $put_into.$file);
        } elseif ($file != "." and $file != ".." and is_dir($directory.$file) and !in_array($this->exclude)) {
          $this->addDirectory($put_into.$file."/");
          $this->get_files_from_folder($directory.$file."/", $put_into.$file."/");
        }
      }
    }
    closedir($handle);
  }
}


$createZip = new createDirZip;
$createZip->exclude = array("somefolder1", "somefolder2");
$createZip->addDirectory("/");
$createZip->get_files_from_folder("./", "/");

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

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

?>

============

If you need any other information etc than please check out http://www.ajayvibha.com/olaf/test.php Visit through proxy  which I have made for your only

Regards,
Ajay
Chicken-run Manager
*
Posts: 9
58 credits
Members referred : 0


« Reply #13 on: Nov 01, 2007, 06:25:15 AM »

I have tried a lot but no success in excluding the folder names.

Can someone help

Thanks & Regards,
Ajay
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #14 on: Nov 02, 2007, 12:16:13 AM »

just found here some error:

} elseif ($file != '.' and $file != '..' and is_dir($directory.$file) and !in_array($this->exclude)) {

must be

} elseif ($file != '.' and $file != '..' and is_dir($directory.$file) and !in_array($file, $this->exclude)) {


Last blog : Is your website is down? Know before your visitors do!
Chicken-run Manager
*
Posts: 9
58 credits
Members referred : 0


« Reply #15 on: Nov 02, 2007, 06:28:37 AM »

=>Yes it is working now olaf, very good work indeed.Everything I have kept at http://www.ajayvibha.com/olaf/test.php Visit through proxy

=> In the same way is it possible to exclude some set of files also e.g exlide all the files php files (*.php) OR some specific files like ( xyz.php) etc.This will make this application quite flexible

=> I have made an online unzip file which is doing fine on local pc but on a php5 & php5 server it is not working.

All the details are at http://www.ajayvibha.com/olaf/test.php Visit through proxy.

Following is the code of the unzip file :-

<?PHP
// create object
$zip = new ZipArchive();   

// open archive
if ($zip->open('sample.zip') !== TRUE) {
    die ("Could not open archive");
}

// extract contents to destination directory
$zip->extractTo('./');

// close archive
// print success message
$zip->close();   
echo "Archive extracted to directory";
?>

Whenever you find time just try it out.This will also to complete the application for php4 & php5 supported servers.

Regards,
Ajay Jain
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #16 on: Nov 02, 2007, 09:44:56 AM »

I would say that you need to give some permissions to the target directory


Last blog : Is your website is down? Know before your visitors do!
Atari ST fan
*
Posts: 7
42 credits
Members referred : 0


« Reply #17 on: Nov 13, 2007, 12:09:48 AM »

Hi guys,

Could anyone please tell me how can I exclude some files like index.php ?
I have tried a lot but no success.

Regards,
Alex
« Last Edit: Nov 13, 2007, 12:24:31 AM by alexro »
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #18 on: Nov 13, 2007, 08:08:57 AM »

Hi guys,

Could anyone please tell me how can I exclude some files like index.php ?
I have tried a lot but no success.

Regards,
Alex

Huh check this thread...


Last blog : Is your website is down? Know before your visitors do!
Atari ST fan
*
Posts: 7
42 credits
Members referred : 0


« Reply #19 on: Nov 13, 2007, 10:39:23 AM »

Could you be more specific please ?
For example on
__
$createZip->exclude = array("somefolder1", "somefolder2");

I tried to replace folder with files like
__
$createZip->exclude = array("index.php", "somefile.php");

but doesn't work.

PS. I'm new in PHP.

Regards,
Alex
« Last Edit: Nov 13, 2007, 10:43:11 AM by alexro »
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?
Sep 05, 2008, 04:54:52 PM





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: 36.293
Total Topics: 7.476
Total Members: 3.899
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: speedy5044

26 Guests, 4 Users online :

16 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.