add() public method

The method return false and a PEAR error text. The files and directories listed are only added at the end of the archive, even if a file with the same name is already archived. See also createModify() method for more details.
See also: createModify()
public add ( array $p_filelist ) : true
$p_filelist array An array of filenames and directory names, or a single string with names separated by a single blank space.
return true on success, false on error.
示例#1
0
 /**
  * Method to create an archive file
  *
  * @param  string|array $files
  * @return void
  */
 public function addFiles($files)
 {
     if (!is_array($files)) {
         $files = array($files);
     }
     foreach ($files as $file) {
         // If file is a directory, loop through and add the files.
         if (file_exists($file) && is_dir($file)) {
             $realpath = realpath($file);
             $dir = new Dir($file, true, true);
             $dirFiles = $dir->getFiles();
             foreach ($dirFiles as $fle) {
                 if (file_exists($fle) && !is_dir($fle)) {
                     $fle = $file . DIRECTORY_SEPARATOR . str_replace($realpath . DIRECTORY_SEPARATOR, '', $fle);
                     $this->archive->add($fle);
                 }
             }
             // Else, just add the file.
         } else {
             if (file_exists($file)) {
                 $this->archive->add($file);
             }
         }
     }
 }
示例#2
0
 /**
  * Add a file to the archive
  *
  * @param string $file The file to add
  *
  * @since 1.0.0
  */
 public function add($file)
 {
     $this->tar->add($file);
 }
示例#3
0
$candidateData = $mriData->getCandidateData($scanTypes);
$mriDataDictionary = $mriData->getDataDictionary($scanTypes);
//add all dictionary names as excel column headings
foreach ($mriDataDictionary as $dicKey => $dicVal) {
    //if column not already present
    if (!array_key_exists($dicKey, $candidateData[0])) {
        $candidateData[0][$dicKey] = NULL;
    }
}
writeExcel($Test_name, $candidateData, $dataDir);
// Clean up
// tar and gzip the product
$tarFile = $dumpName . ".tgz";
// produced dump file name and extension
$tar = new Archive_Tar($tarFile, "gz");
$tar->add("./{$dumpName}/") or die("Could not add files!");
// mv (or as php calls it, 'rename') to a web-accessible pickup directory
rename("./{$tarFile}", "{$destinationDir}/{$tarFile}");
//change, if not a subdirectory
// rm left-over junk, from all that excel file generation.
delTree($dataDir);
// Announce completion
echo "{$tarFile} ready in {$destinationDir}\n";
/**
 * Takes a 2D array and saves it as a nicely formatted Excel spreadsheet.
 * Metadata columns are preserved, multiple worksheets are used, when appropriate and headers are maintained.
 *
 * @param string	$Test_name	File name to be used.
 * @param unknown_type $instrument_table 	A 2D array of the data to be presented in Excel format
 * @param unknown_type $dataDir The  output directory.
 */
示例#4
0
 // Increase script execution time-limit to 15 min for archiving.
 if (!ini_get('safe_mode')) {
     @set_time_limit(15 * 60);
 }
 // create Archive_Tar() object
 require_once dirname(__FILE__) . '/Tar.php';
 // Compress the archive file
 if ($archive_gzip) {
     log_msg(date("H:i:s") . ": Archiving SQL files in " . $db_backup_fname . ".gz ...\n");
     $tar = new Archive_Tar(DB_BACKUP_PATH . "/" . $db_backup_fname . ".gz", "gz");
 } else {
     log_msg(date("H:i:s") . ": Archiving SQL files in " . $db_backup_fname . " ...\n");
     $tar = new Archive_Tar(DB_BACKUP_PATH . "/" . $db_backup_fname);
 }
 // Build archive
 if ($tar->add("days weeks months")) {
     log_msg(date("H:i:s") . ": Archiving succesfull.\n");
     log_msg($sep);
     // Remove the SQL files
     if ($archive_del_sql) {
         log_msg(date("H:i:s") . ": Removing SQL-files ...\n");
         del_sql_files("days");
         del_sql_files("weeks");
         del_sql_files("months");
         chdir(DB_BACKUP_PATH);
         if (rmdir($db_name)) {
             log_msg(date("H:i:s") . ": Directory \"{$db_name}\" removed.\n");
         } else {
             log_msg(date("H:i:s") . ": Error removing directory \"{$db_name}\"!\n", 20);
             $db_error_count++;
         }