Difference between revisions of "JArchive/extract"
From Joomla! Documentation
< API15:JArchive
(New page:
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki>
</span>
{{Description:JArchive/extract}}
=...) |
m (removing red link to edit, no existant pages) |
||
Line 1: | Line 1: | ||
− | |||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Syntax=== | ===Syntax=== | ||
Line 138: | Line 137: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
Line 153: | Line 152: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API15]] |
Revision as of 08:42, 12 May 2013
The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
extract($archivename, $extractdir)
Parameter Name | Default Value | Description |
---|---|---|
$archivename | The name of the archive file | |
$extractdir | Directory to unpack into |
Returns[edit]
boolean True for success
Defined in[edit]
libraries/joomla/filesystem/archive.php
Importing[edit]
jimport( 'joomla.filesystem.archive' );
Source Body[edit]
function extract( $archivename, $extractdir)
{
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
$untar = false;
$result = false;
$ext = JFile::getExt(strtolower($archivename));
// check if a tar is embedded...gzip/bzip2 can just be plain files!
if (JFile::getExt(JFile::stripExt(strtolower($archivename))) == 'tar') {
$untar = true;
}
switch ($ext)
{
case 'zip':
$adapter =& JArchive::getAdapter('zip');
if ($adapter) {
$result = $adapter->extract($archivename, $extractdir);
}
break;
case 'tar':
$adapter =& JArchive::getAdapter('tar');
if ($adapter) {
$result = $adapter->extract($archivename, $extractdir);
}
break;
case 'tgz' :
$untar = true; // This format is a tarball gzip'd
case 'gz' : // This may just be an individual file (e.g. sql script)
case 'gzip' :
$adapter =& JArchive::getAdapter('gzip');
if ($adapter)
{
$config =& JFactory::getConfig();
$tmpfname = $config->getValue('config.tmp_path').DS.uniqid('gzip');
$gzresult = $adapter->extract($archivename, $tmpfname);
if (JError::isError($gzresult))
{
@unlink($tmpfname);
return false;
}
if($untar)
{
// Try to untar the file
$tadapter =& JArchive::getAdapter('tar');
if ($tadapter) {
$result = $tadapter->extract($tmpfname, $extractdir);
}
}
else
{
$path = JPath::clean($extractdir);
JFolder::create($path);
$result = JFile::copy($tmpfname,$path.DS.JFile::stripExt(JFile::getName(strtolower($archivename))));
}
@unlink($tmpfname);
}
break;
case 'tbz2' :
$untar = true; // This format is a tarball bzip2'd
case 'bz2' : // This may just be an individual file (e.g. sql script)
case 'bzip2':
$adapter =& JArchive::getAdapter('bzip2');
if ($adapter)
{
$config =& JFactory::getConfig();
$tmpfname = $config->getValue('config.tmp_path').DS.uniqid('bzip2');
$bzresult = $adapter->extract($archivename, $tmpfname);
if (JError::isError($bzresult))
{
@unlink($tmpfname);
return false;
}
if ($untar)
{
// Try to untar the file
$tadapter =& JArchive::getAdapter('tar');
if ($tadapter) {
$result = $tadapter->extract($tmpfname, $extractdir);
}
}
else
{
$path = JPath::clean($extractdir);
JFolder::create($path);
$result = JFile::copy($tmpfname,$path.DS.JFile::stripExt(JFile::getName(strtolower($archivename))));
}
@unlink($tmpfname);
}
break;
default:
JError::raiseWarning(10, JText::_('UNKNOWNARCHIVETYPE'));
return false;
break;
}
if (! $result || JError::isError($result)) {
return false;
}
return true;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
<CodeExamplesForm />