Archive_Tar::addString PHP Method

addString() public method

This method add a single string as a file at the end of the existing archive. If the archive does not yet exists it is created.
public addString ( string $p_filename, string $p_string ) : true
$p_filename string A string which contains the full filename path that will be associated with the string.
$p_string string The content of the file added in the archive.
return true on success, false on error.
    function addString($p_filename, $p_string)
    {
        $v_result = true;
        if (!$this->_isArchive()) {
            if (!$this->_openWrite()) {
                return false;
            }
            $this->_close();
        }
        if (!$this->_openAppend()) {
            return false;
        }
        // Need to check the get back to the temporary file ? ....
        $v_result = $this->_addString($p_filename, $p_string);
        $this->_writeFooter();
        $this->_close();
        return $v_result;
    }

Usage Example

 public static function generateTarByPluginDir(array $info, $filename, $input, $output)
 {
     $timeLimit = ini_get('max_execution_time');
     set_time_limit(0);
     require_once 'Archive/Tar.php';
     $tar = new Archive_Tar($output . '/' . $filename, true);
     foreach ($info['filelist'] as $file => $data) {
         $tar->addString($info['name'] . '-' . $info['version'] . '/' . $file, file_get_contents($input . '/' . $file));
     }
     $tar->addString('package.xml', file_get_contents($input . '/package.xml'));
     set_time_limit($timeLimit);
 }
All Usage Examples Of Archive_Tar::addString