Forum Moderators: coopster
I realise that the following code lets you unzip the contents of a zip file in the same directory:
<?php system('unzip zipFileName.zip'); ?> But is there an easy way to do the reverse? It's so that I can zip up my website public_html folder and download it easily.
I tried this, but it didn't work:
<?php system('zip zipFolderName'); ?> Cheers
Sorry, yes of course. It literally doesn't do anything when I run the script - I tried putting in this code to see if it was working (I assume this is the way to do it, sorry I'm still learning):
<?php if (system('zip zipmeup.zip')) {
echo 'Zipped';
} else {
echo 'failed';
}
?>
And it says 'failed', so I assume it's not running. Do I need to change directory or something for this to work?
Thanks for getting back to me
I'm assuming you are doing this for yourself? Meaning, you don't have command line access to your server and this is something of a backup you are creating for yourself? If so, most hosts provide some form of backup option when they do not allow you command line access. You may want to check in your control panel.
Cheers,
<?php
// Set path to download zip file
$dl_url = 'http://www.domainname.com/_backup/filename.zip';// Check if everything's cool and groovy - create a link to download zip file
if (system('zip -r /home/path/domain/_backup/filename.zip /home/path/domain'))
{
echo '<p>All zipped up!</p>';
echo '<a href="' . $dl_url . '">Download</a>';
} else {
echo '<p>Balls! Didn\'t work.</p>';
}
?>