I am creating a php backup script that will dump everything from a database and save it to a file. I have been successful in doing that but now I need to take hundreds of images in a directory and compress them into one simple .tar.gz file.
What is the best way to do this and how is it done? I have no idea where to start.
Thanks in advance
If you are using PHP 5.2 or later, you could use the Zip Library
and then do something along the lines of:
You can easily gzip a folder using this command:
This command can be ran through phps system()-function.
Don't forget to escapeshellarg() all commands.
Chosen answer doesn't support recursion (subdirectories), so here you go:
My simple 2 lines PHP file by which I can create a backup ZIP file within a few seconds:
Just browse: http://mysiteurl.com/create-my-zip.php
Simply upload this file into the server and browse directly.
Notes:
You can also use something like this:
Be sure to heed the warnings about using PHP's
exec()
function.