PHP can execute shell commands, which means it can compress selected files into a archive or zipped package:
exec('tar zcf files.tar.gz file1 file2 file3');
Or make a zip file:
exec('zip files.zip file1 file2 file3');
You can then use PHP to render and supply download of the zip file to your visitor.
3 replies on “PHP: Compress Files into Tar or Zip – Make A Zip File or Tar File with PHP”
[…] will start dumping all databases into a text SQL file: all.sql. After it’s done, you can compress (“tar zcf all.tar.gz all.sqlâ€) and put all.sql somewhere safe for […]
[…] I should use “zipped†for an RAR compressed package. Anyway, you can easily zip or unzip a zip file or tar compress a package, but how does one do it with an RAR file? WinRAR is well distributed across all Windows systems. […]
[…] validation, change the file name and move it somewhere below webroot. You can also optionally tar it for […]