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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.