Added the tar plugin
[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 #$out = exec("du -c $filesarg");
31 #preg_match('/^([0-9]+).*total$/', $out, $matches);
32 #$totalsize = $matches[1] * 1024;
33
34 #var_dump($totalsize);
35
36 #var_dump("tar --no-recursion -c $filesarg");
37 #die();
38
39 header("Content-Length: $totalsize");
40 header('Content-Type: application/x-tar');
41 header('Content-Disposition: attachment; filename="'.basename($realDir).'.tar"');
42
43 passthru("tar --no-recursion -c $filesarg");
44
45 ?>