--- tar.module 2008-09-26 18:31:17.000000000 +0100 +++ tar.module 2009-09-26 11:45:53.000000000 +0100 @@ -9,6 +9,7 @@ */ define('TAR_GZIP', 0x01); +define('TAR_DIRONLY', 0x02); /* ----------------------------------------------------------------------- @@ -44,6 +45,7 @@ * @param int $options * (optional) Available bitmask flags: * - TAR_GZIP + * - TAR_DIRONLY * * @return mixed * - int: Error occured. @@ -68,9 +70,9 @@ // Create archive if ($dest = file_create_path($dest)){ if (file_check_directory($dest, FILE_CREATE_DIRECTORY)){ - $o = 'cf'; + $o = '-c'; $filename = !empty($filename) ? $filename : 'archive'; - $extension = $options & TAR_GZIP ? '.gz' : '.tar'; + $extension = $options & TAR_GZIP ? '.tar.gz' : '.tar'; $filepath = './' . $dest . '/' . $filename . $extension; // Remove previous archives @@ -79,11 +81,16 @@ } // Options - if ($options & TAR_GZIP){ $o = 'czf'; } + if ($options & TAR_GZIP) { $o .= ' -z '; } + if ($options & TAR_DIRONLY) { + $dirname = dirname($dir); + $dir = basename($dir); + $o .= " -C \"$dirname\" "; + } // Create archive // @todo security - `tar -$o "$filepath" "$dir"`; + `tar $o -f "$filepath" "$dir"`; // Return the newly created tar filepath return $filepath;