Some cleanup in tar.php
[bizou.git] / plugins / tar / tar.php
1 <?php
2
3 $bizouRootFromHere = '../..';
4 require "$bizouRootFromHere/config.php";
5
6 if (isset($_SERVER["PATH_INFO"])) {
7         $simplePath = $_SERVER["PATH_INFO"];
8 } else {
9         $simplePath = '/';
10 }
11
12 if (strpos($simplePath, '..') !== false) die(".. found in url");
13
14 $realDir = "$bizouRootFromHere/".IMAGES_DIR.$simplePath;
15
16 if ( ! is_dir($realDir) ) {
17         header("HTTP/1.1 404 Not Found");
18         die("Directory Not Found");
19 }
20
21 # change to the parent directory
22 chdir(dirname($realDir));
23
24 $filesarg = escapeshellarg(basename($realDir))."/*";
25
26 $out = exec("tar --no-recursion --totals -cf /dev/null $filesarg 2>&1");
27 preg_match('/^Total bytes written: ([0-9]+) /', $out, $matches);
28 $totalsize = $matches[1];
29
30 header("Content-Length: $totalsize");
31 header('Content-Type: application/x-tar');
32 header('Content-Disposition: attachment; filename="'.basename($realDir).'.tar"');
33
34 passthru("tar --no-recursion -c $filesarg");
35
36 ?>