Actions

API15

Difference between revisions of "JArchiveTar/extract"

From Joomla! Documentation

< API15:JArchiveTar
(New page: ===Description=== Extract a ZIP compressed file to a given path <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton...)
 
m (removing red link to edit, no existant pages)
 
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JArchiveTar/extract|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JArchiveTar/extract}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 82: Line 82:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JArchiveTar/extract|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JArchiveTar/extract}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 97: Line 97:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API15]]

Latest revision as of 08:42, 12 May 2013

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Extract a ZIP compressed file to a given path

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

extract($archive, $destination, $options=array())
Parameter Name Default Value Description
$archive $archive Path to ZIP archive to extract
$destination $destination Path to extract archive into
$options array() $options Extraction options [unused]

Returns

boolean True if successful

Defined in

libraries/joomla/filesystem/archive/tar.php

Importing

jimport( 'joomla.filesystem.archive.tar' );

Source Body

function extract($archive, $destination, $options = array ())
{
        // Initialize variables
        $this->_data = null;
        $this->_metadata = null;
 
        if (!$this->_data = JFile::read($archive))
        {
                $this->set('error.message', 'Unable to read archive');
                return JError::raiseWarning(100, $this->get('error.message'));
        }
 
        if (!$this->_getTarInfo($this->_data))
        {
                return JError::raiseWarning(100, $this->get('error.message'));
        }
 
        for ($i=0,$n=count($this->_metadata);$i<$n;$i++)
        {
                $type   = strtolower( $this->_metadata[$i]['type'] );
                if ($type == 'file' || $type == 'unix file')
                {
                        $buffer = $this->_metadata[$i]['data'];
                        $path = JPath::clean($destination.DS.$this->_metadata[$i]['name']);
                        // Make sure the destination folder exists
                        if (!JFolder::create(dirname($path)))
                        {
                                $this->set('error.message', 'Unable to create destination');
                                return JError::raiseWarning(100, $this->get('error.message'));
                        }
                        if (JFile::write($path, $buffer) === false)
                        {
                                $this->set('error.message', 'Unable to write entry');
                                return JError::raiseWarning(100, $this->get('error.message'));
                        }
                }
        }
        return true;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />