Use short tags for php echo
[bizou.git] / plugins / tar / tar.php
index 3554622..9d3a46f 100644 (file)
@@ -1,4 +1,21 @@
 <?php
+/*
+    Bizou - a (french) KISS php image gallery
+    Copyright (C) 2010  Marc MAURICE
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
 # do not enable recursive tars by default
 $TAR_FLAGS = "--no-recursion";
@@ -31,14 +48,19 @@ if ( ! is_dir($realDir) ) {
 # change to the parent directory
 chdir(dirname($realDir));
 
-$filesarg = escapeshellarg(basename($realDir))."/*";
+$filesarg = basename($realDir);
+# same as escapeshellarg function but this supports utf8 regardless of locale
+$filesarg = "'".str_replace("'", "'\\''", $filesarg)."'";
+$filesarg = "$filesarg/*";
 
 # compute and send content-length header
 if ($SEND_CONTENT_LENGTH) {
-       $out = exec("tar $TAR_FLAGS --totals -cf /dev/null $filesarg 2>&1");
+       $out = exec("tar $TAR_FLAGS --totals -cf /dev/null $filesarg 2>&1", $output, $ret);
        preg_match('/^Total bytes written: ([0-9]+) /', $out, $matches);
        $totalsize = $matches[1];
 
+       ($totalsize > 1000 and $ret === 0) or die("Could not tar: $filesarg. Try checking permissions.");
+
        header("Content-Length: $totalsize");
 }