3 # do not enable recursive tars by default
4 $TAR_FLAGS = "--no-recursion";
6 # send content length for browsers to display the progress bar
7 # note : won't work if the http server uses Chunked transfer encoding (http://en.wikipedia.org/wiki/Chunked_transfer_encoding)
8 # probably the case with gzip content-encoding.
9 # For this we need to tar files to /dev/null before the real tar
10 $SEND_CONTENT_LENGTH = true;
12 ########################
13 $bizouRootFromHere = '../..';
14 require "$bizouRootFromHere/config.php";
16 if (isset($_SERVER["PATH_INFO"])) {
17 $simplePath = $_SERVER["PATH_INFO"];
22 if (strpos($simplePath, '..') !== false) die(".. found in url");
24 $realDir = "$bizouRootFromHere/".IMAGES_DIR.$simplePath;
26 if ( ! is_dir($realDir) ) {
27 header("HTTP/1.1 404 Not Found");
28 die("Directory Not Found");
31 # change to the parent directory
32 chdir(dirname($realDir));
34 $filesarg = escapeshellarg(basename($realDir))."/*";
36 # compute and send content-length header
37 if ($SEND_CONTENT_LENGTH) {
38 $out = exec("tar $TAR_FLAGS --totals -cf /dev/null $filesarg 2>&1");
39 preg_match('/^Total bytes written: ([0-9]+) /', $out, $matches);
40 $totalsize = $matches[1];
42 header("Content-Length: $totalsize");
45 # final step : stream the directory content via tar
46 header('Content-Type: application/x-tar');
47 header('Content-Disposition: attachment; filename="'.basename($realDir).'.tar"');
49 passthru("tar $TAR_FLAGS -c $filesarg");