xeirus Posted November 20, 2011 Share Posted November 20, 2011 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 https://forums.phpfreaks.com/topic/251502-compress-a-directory-and-all-its-multilevel-subdirectories-using-php-tar-and-gz/ Share on other sites More sharing options...
trq Posted November 20, 2011 Share Posted November 20, 2011 exec("tar -cvf - $dir | gzip -c > $tar.tar.gz"); Where $dir is a variable containing the path of the directory you want to compress and $tar is the name / path of the tar.gz file you wish to create. Link to comment https://forums.phpfreaks.com/topic/251502-compress-a-directory-and-all-its-multilevel-subdirectories-using-php-tar-and-gz/#findComment-1289855 Share on other sites More sharing options...
xeirus Posted November 20, 2011 Author Share Posted November 20, 2011 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. Link to comment https://forums.phpfreaks.com/topic/251502-compress-a-directory-and-all-its-multilevel-subdirectories-using-php-tar-and-gz/#findComment-1289858 Share on other sites More sharing options...
tomfmason Posted November 21, 2011 Share Posted November 21, 2011 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? Link to comment https://forums.phpfreaks.com/topic/251502-compress-a-directory-and-all-its-multilevel-subdirectories-using-php-tar-and-gz/#findComment-1289863 Share on other sites More sharing options...
xeirus Posted November 21, 2011 Author Share Posted November 21, 2011 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 https://forums.phpfreaks.com/topic/251502-compress-a-directory-and-all-its-multilevel-subdirectories-using-php-tar-and-gz/#findComment-1289894 Share on other sites More sharing options...
trq Posted November 21, 2011 Share Posted November 21, 2011 Post your code. Link to comment https://forums.phpfreaks.com/topic/251502-compress-a-directory-and-all-its-multilevel-subdirectories-using-php-tar-and-gz/#findComment-1289896 Share on other sites More sharing options...
xeirus Posted November 21, 2011 Author Share Posted November 21, 2011 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 https://forums.phpfreaks.com/topic/251502-compress-a-directory-and-all-its-multilevel-subdirectories-using-php-tar-and-gz/#findComment-1289902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.