Web Hosting Talk







View Full Version : Dynamicly Taring a directory


Aushosts
11-26-2002, 03:24 AM
Hi Everyone,

I need a PHP script that can tar/zip up a directory on the server so I can download it via http.
Reason is I wrote a script that uses txt files and PHP has edited them, so downloading via ftp seem to corrupt them for some crazy reason.
Does anyone know of such of program/script?

MarkIL
11-26-2002, 08:36 AM
Hmm... This may pose somewhat of a security risk, but assuming that $dir is a valid directory name...


ob_start();
header("Content-type: application/x-tar");
$s = sprintf("tar cfp /tmp/%s.tar %s",$dir,$dir);
@exec($s);
if (file_exists("/tmp/{$dir}.tar")) readfile("/tmp/{$dir}.tar");
ob_end_flush();

Aushosts
11-26-2002, 09:08 AM
Only out puts a empty page, does not send a file...

<?
$dir = "/usr/local/psa/home/vhosts/townsvillecricket.com/httpdocs";
ob_start();

header("Content-type: application/x-tar");

$s = sprintf("tar cfp /tmp/%s.tar %s",$dir,$dir);

@exec($s);

if (file_exists("/tmp/{$dir}.tar")) readfile("/tmp/{$dir}.tar");

ob_end_flush();
?>