Jump to content

Compress a directory and all its multilevel subdirectories using php, tar and gz


xeirus

Recommended Posts

Hi!

I need a "very simple" PHP script which can compress a directory and all its multi-(infinite)level sub-directories using with .tar and .gz

I have tried many complex scripts so far which don't work as most of them use ZIP and I don't have access to ZIP

And a few of the simple ones, just don't function.

 

Please help!

 

Thank you !

 

- Xeirus.

Thanks for your reply thorpe.

But it doesn't seem to work.

Throws out a file with the name .tar.gz and file size of 45 bytes.

 

 

did you define the $dir and $tar variables?

I'm very sorry, tomfmason

I messed up on the $tar, overlooked it, been trying this whole evening, guess I was tired.

Apologies to you too, thorpe!

 

Anyway, it seemed to have worked the first time, threw out a 150+MBs worth of a tar.gz file but since then I changed the file name to:

tar2.tar.gz

tar4.tar.gz

tar6.tar.gz

And only throws out a 20 byte worth of files, each time.

 

Any ideas?

Thorpe,

Here's your given code and the way I've modified it with just a variable:

$backupImagesDirFilename = 'images-' . date("Y-m-d-H-i-s");
exec("tar -cvf - ../images/ | gzip -c > $backupImagesDirFilename.tar.gz");

 

and here's another person's code ... which does seem to work:

$backupImagesDirFilename = 'images-' . date("Y-m-d-H-i-s");
exec("tar cvfz $backupImagesDirFilename.tgz ../images/ >$backupImagesDirFilename-results.txt");

 

but here's my next problem which I almost saw coming:

It seems to do this in background, I mean, if a user doesn't know that something is happening then they might hit refresh or something.

Is there any way I can actually tell the end-user to wait while the zip is being prepared and when it is REALLY finished then it asks the user to continue?

 

I can do a fake echo but that won't help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.