Open Journal Systems  3.3.0
FileArchive.inc.php
1 <?php
2 
16 class FileArchive {
17 
18  function __construct() {
19  }
20 
30  function create($files, $filesDir) {
31  // Create a temporary file.
32  $archivePath = tempnam('/tmp', 'sf-');
33 
34  // attempt to use Zip first, if it is available. Otherwise
35  // fall back to the tar CLI.
36  $zipTest = false;
37  if (self::zipFunctional()) {
38  $zipTest = true;
39  $zip = new ZipArchive();
40  if ($zip->open($archivePath, ZIPARCHIVE::CREATE) == true) {
41  foreach ($files as $serverPath => $clientFilename) {
42  $zip->addFile($filesDir . '/' . $serverPath, $clientFilename);
43  }
44  $zip->close();
45  }
46  } elseif (self::tarFunctional()) {
47  // Create the archive and download the file.
48  exec(Config::getVar('cli', 'tar') . ' -c -z ' .
49  '-f ' . escapeshellarg($archivePath) . ' ' .
50  '-C ' . escapeshellarg($filesDir) . ' ' .
51  implode(' ', array_map('escapeshellarg', array_keys($files)))
52  );
53  } else {
54  throw new Exception('No archive tool is available!');
55  }
56 
57  return $archivePath;
58  }
59 
64  static function zipFunctional() {
65  return (extension_loaded('zip'));
66  }
67 
71  static function tarFunctional() {
72  $tarBinary = Config::getVar('cli', 'tar');
73  return !empty($tarBinary) && file_exists($tarBinary);
74  }
75 
76  static function isFunctional() {
78  }
79 }
80 
81 
FileArchive\isFunctional
static isFunctional()
Definition: FileArchive.inc.php:76
FileArchive
Class provides functionality for creating an archive of files.
Definition: FileArchive.inc.php:16
FileArchive\create
create($files, $filesDir)
Definition: FileArchive.inc.php:30
FileArchive\zipFunctional
static zipFunctional()
Definition: FileArchive.inc.php:64
Config\getVar
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
FileArchive\__construct
__construct()
Definition: FileArchive.inc.php:18
FileArchive\tarFunctional
static tarFunctional()
Definition: FileArchive.inc.php:71