本文整理汇总了PHP中PclZip::errorName方法的典型用法代码示例。如果您正苦于以下问题:PHP PclZip::errorName方法的具体用法?PHP PclZip::errorName怎么用?PHP PclZip::errorName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PclZip
的用法示例。
在下文中一共展示了PclZip::errorName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkZip
function checkZip()
{
include_once SERVER_ROOT . "core/inc/lib/pclzip.php";
$zip = new PclZip(SERVER_ROOT . "cache/update.zip");
$zip->listContent();
if ($zip->errorName() != "PCLZIP_ERR_NO_ERROR") {
return false;
}
return true;
}
示例2: extractArchive
/**
* Extracts the package archive file
* @return boolean True on success, False on error
*/
function extractArchive()
{
global $mosConfig_absolute_path;
$base_Dir = mosPathName($mosConfig_absolute_path . '/media');
$archivename = $base_Dir . $this->installArchive();
$tmpdir = uniqid('install_');
$extractdir = mosPathName($base_Dir . $tmpdir);
$archivename = mosPathName($archivename, false);
$this->unpackDir($extractdir);
if (eregi('.zip$', $archivename)) {
// Extract functions
require_once $mosConfig_absolute_path . '/administrator/includes/pcl/pclzip.lib.php';
require_once $mosConfig_absolute_path . '/administrator/includes/pcl/pclerror.lib.php';
//require_once( $mosConfig_absolute_path . '/administrator/includes/pcl/pcltrace.lib.php' );
//require_once( $mosConfig_absolute_path . '/administrator/includes/pcl/pcltar.lib.php' );
$zipfile = new PclZip($archivename);
if ($this->isWindows()) {
define('OS_WINDOWS', 1);
} else {
define('OS_WINDOWS', 0);
}
$ret = $zipfile->extract(PCLZIP_OPT_PATH, $extractdir);
if ($ret == 0) {
$this->setError(1, 'Unrecoverable error "' . $zipfile->errorName(true) . '"');
return false;
}
} else {
require_once $mosConfig_absolute_path . '/includes/Archive/Tar.php';
$archive = new Archive_Tar($archivename);
$archive->setErrorHandling(PEAR_ERROR_PRINT);
if (!$archive->extractModify($extractdir, '')) {
$this->setError(1, 'Extract Error');
return false;
}
}
$this->installDir($extractdir);
// Try to find the correct install dir. in case that the package have subdirs
// Save the install dir for later cleanup
$filesindir = mosReadDirectory($this->installDir(), '');
if (count($filesindir) == 1) {
if (is_dir($extractdir . $filesindir[0])) {
$this->installDir(mosPathName($extractdir . $filesindir[0]));
}
}
return true;
}
示例3: PclZip
<?php
include BigTree::path("inc/lib/pclzip.php");
$zip = new PclZip(SERVER_ROOT . "cache/update.zip");
$zip->listContent();
if ($zip->errorName() != "PCLZIP_ERR_NO_ERROR") {
?>
<div class="container">
<summary><h2>Upgrade BigTree</h2></summary>
<section>
<p>An error occurred extracting the zip file. You can hit back to try the download again or click the ignore button below to try the auto upgrade again in a week.</p>
</section>
<footer>
<a class="button blue" href="<?php
echo DEVELOPER_ROOT;
?>
upgrade/init/?type=<?php
echo htmlspecialchars($_GET["type"]);
?>
">Try Again</a>
<a class="button" href="<?php
echo DEVELOPER_ROOT;
?>
upgrade/remind/">Remind Me Later</a>
</footer>
</div>
<?php
} else {
// See if we can write to the root directory
if (is_writable(SERVER_ROOT) && is_writable(SERVER_ROOT . "core/")) {
$writable = true;
示例4: extractArchive
/**
* Extracts the package archive file
* @return boolean True on success, False on error
*/
function extractArchive()
{
$base_Dir = DOCMAN_Compat::mosPathName(JPATH_ROOT . '/media');
$archivename = $base_Dir . $this->installArchive();
$tmpdir = uniqid('install_');
$extractdir = DOCMAN_Compat::mosPathName($base_Dir . $tmpdir);
$archivename = DOCMAN_Compat::mosPathName($archivename, false);
$this->unpackDir($extractdir);
if (preg_match('/.zip$/i', $archivename)) {
// Extract functions
require_once JPATH_ADMINISTRATOR . DS . 'includes' . DS . 'pcl' . DS . 'pclzip.lib.php';
require_once JPATH_ADMINISTRATOR . DS . 'includes' . DS . 'pcl' . DS . 'pclerror.lib.php';
$zipfile = new PclZip($archivename);
if ($this->isWindows()) {
define('OS_WINDOWS', 1);
} else {
define('OS_WINDOWS', 0);
}
$ret = $zipfile->extract(PCLZIP_OPT_PATH, $extractdir);
if ($ret == 0) {
$this->setError(1, 'Unrecoverable error "' . $zipfile->errorName(true) . '"');
return false;
}
} else {
require_once JPATH_ROOT . DS . 'includes' . DS . 'Archive' . DS . 'Tar.php';
$archive = new Archive_Tar($archivename);
$archive->setErrorHandling(PEAR_ERROR_PRINT);
if (!$archive->extractModify($extractdir, '')) {
$this->setError(1, 'Extract Error');
return false;
}
}
$this->installDir($extractdir);
// Try to find the correct install dir. in case that the package have subdirs
// Save the install dir for later cleanup
$filesindir = DOCMAN_Compat::mosReadDirectory($this->installDir(), '');
if (count($filesindir) == 1) {
if (is_dir($extractdir . $filesindir[0])) {
$this->installDir(DOCMAN_Compat::mosPathName($extractdir . $filesindir[0]));
}
}
return true;
}
示例5: extractArchive
/**
* Extracts the package archive file
* @return boolean True on success, False on error
*/
public function extractArchive()
{
$base_Dir = JPath::clean(JPATH_BASE . '/media');
$archivename = $base_Dir . $this->_realname;
$tmpdir = uniqid('install_');
$extractdir = JPath::clean($base_Dir . $tmpdir);
$archivename = JPath::clean($archivename, false);
$this->_unpackdir = $extractdir;
if (preg_match('/.zip$/', $archivename)) {
// Extract functions
require_once JPATH_ADMINISTRATOR . '/includes/pcl/pclzip.lib.php';
require_once JPATH_ADMINISTRATOR . '/includes/pcl/pclerror.lib.php';
$zipfile = new PclZip($this->_uploadfile);
if ($this->_iswin) {
define('OS_WINDOWS', 1);
} else {
define('OS_WINDOWS', 0);
}
$ret = $zipfile->extract(PCLZIP_OPT_PATH, $extractdir);
if ($ret == 0) {
$this->errno = 1;
$this->error = 'Unrecoverable error "' . $zipfile->errorName(true) . '"';
return false;
}
} else {
require_once JPATH_SITE . '/includes/Archive/Tar.php';
$archive = new Archive_Tar($this->_uploadfile);
$archive->setErrorHandling(PEAR_ERROR_PRINT);
if (!$archive->extractModify($extractdir, '')) {
$this->setError(1, 'Extract Error');
return false;
}
}
// Try to find the correct install dir. in case that the package have subdirs
// Save the install dir for later cleanup
jimport('joomla.filesystem.folder');
$this->_uploadfile = JFolder::files($extractdir, '');
if (count($this->_uploadfile) == 1) {
if (is_dir($extractdir . $this->_uploadfile[0])) {
$this->_unpackdir = JPath::clean($extractdir . $this->_uploadfile[0]);
$this->_uploadfile = JFolder::files($extractdir, '');
}
}
return true;
}
示例6: upload
/**
* Upload a theme into my site
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Samuele Tognini <samuele@samuele.netsons.org>
*/
function upload($theme, $info)
{
$return = true;
$host = 'samuele.netsons.org';
$path = '/dokuwiki/lib/plugins/indexmenu/upload/index.php';
//TODO: merge zip creation with that in ajax.php (create a class?)
if (!($absdir = $this->checktmpsubdir())) {
return false;
}
$tmp = $absdir . "/tmp";
$zipfile = "{$theme}.zip";
$filelist = "{$absdir}/{$theme}";
//create info
if (!empty($info)) {
io_savefile("{$tmp}/{$theme}/info.txt", $info);
$filelist .= ",{$tmp}/{$theme}";
}
//create zip
$zip = new PclZip("{$tmp}/{$zipfile}");
$status = $zip->create($filelist, PCLZIP_OPT_REMOVE_ALL_PATH);
if ($status == 0) {
//error
msg($this->getLang('zip_err') . ": " . $zip->errorName(true), -1);
$return = false;
} else {
//prepare POST headers.
$boundary = "---------------------------" . uniqid("");
$data = join("", file("{$tmp}/{$zipfile}"));
$header = "POST {$path} HTTP/1.0\r\n";
$header .= "Host: {$host}\r\n";
$header .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061024 Iceweasel/2.0 (Debian-2.0+dfsg-1)\r\n";
$header .= "Content-type: multipart/form-data, boundary={$boundary}\r\n";
$body = "--" . $boundary . "\r\n";
$body .= "Content-Disposition: form-data; name=\"userfile\"; filename=\"{$zipfile}\"\r\n";
$body .= "Content-Type: application/x-zip-compressed\r\n\r\n";
$body .= $data . "\r\n";
$body .= "--" . $boundary . "\r\n";
$body .= "Content-Disposition: form-data; name=\"upload\"\r\n\r\n";
$body .= "Upload\r\n";
$body .= "--" . $boundary . "--\r\n";
$header .= "Content-Length: " . strlen($body) . "\r\n\r\n";
//connect and send zip
if ($fp = fsockopen($host, 80)) {
fwrite($fp, $header . $body);
//reply
$buf = "";
while (!feof($fp)) {
$buf .= fgets($fp, 3200);
}
fclose($fp);
//parse resply
if (preg_match("/<!--indexmenu-->(.*)<!--\\/indexmenu-->/s", $buf, $match)) {
$str = substr($match[1], 4, 7);
switch ($str) {
case "ERROR ":
$mesg_type = -1;
break;
case "SUCCESS":
$mesg_type = 1;
break;
default:
$mesg_type = 2;
}
msg($match[1], $mesg_type);
} else {
$return = false;
}
} else {
$return = false;
}
}
$this->_rm_dir($tmp);
return $return;
}
示例7: define
function _compressFiles($name)
{
require_once MAX_PATH . '/lib/pclzip/pclzip.lib.php';
define('OS_WINDOWS', substr(PHP_OS, 0, 3) == 'WIN' ? 1 : 0);
$target = $this->outputDir . $name . '.zip';
$oZip = new PclZip($target);
$result = $oZip->create($this->aFileList, PCLZIP_OPT_REMOVE_PATH, $this->basePath);
if ($oZip->errorCode()) {
$this->aErrors[] = 'compression error: ' . $oZip->errorName(true);
return false;
}
if (!$result || !count($result)) {
$this->aErrors[] = 'no files were compressed';
return false;
}
//$aContents = $oZip->listContent();
$error = !file_exists($target);
if (!$error) {
foreach ($result as $i => $aInfo) {
if ($aInfo['status'] != 'ok') {
switch ($aInfo['status']) {
case 'filename_too_long':
case 'write_error':
case 'read_error':
case 'invalid_header':
$this->aErrors[] = 'Error: ' . $aInfo['status'] . ' : ' . $aInfo['filename'];
$error = true;
break;
case 'filtered':
case 'skipped':
default:
break;
}
}
}
}
return $error ? false : $target;
}
示例8: jimport
function &getPatchContents($updatepackage)
{
global $vmLogger, $mosConfig_absolute_path, $VM_LANG;
$extractdir = vmUpdate::getPackageDir($updatepackage);
$update_manifest = $extractdir . '/update.xml';
$result = true;
if (!file_exists($update_manifest)) {
if (vmIsJoomla('1.5', '>=')) {
jimport('joomla.filesystem.archive');
if (!JArchive::extract($updatepackage, $extractdir)) {
$vmLogger->err($VM_LANG->_('VM_UPDATE_ERR_EXTRACT_FAILED') . " " . $extractdir);
$result = false;
return $result;
}
} else {
$file_info = pathinfo($updatepackage);
switch ($file_info['extension']) {
case 'gz':
require_once ADMINPATH . 'Tar.php';
$package_archive = new Archive_Tar($updatepackage, "gz");
$result = $package_archive->extract($extractdir . '/');
if (!$result) {
$vmLogger->err($VM_LANG->_('VM_UPDATE_ERR_EXTRACT_FAILED') . " " . $extractdir);
$result = false;
return $result;
}
break;
case 'zip':
// Extract functions
require_once $mosConfig_absolute_path . '/administrator/includes/pcl/pclzip.lib.php';
require_once $mosConfig_absolute_path . '/administrator/includes/pcl/pclerror.lib.php';
$zipfile = new PclZip($updatepackage);
$ret = $zipfile->extract(PCLZIP_OPT_PATH, $extractdir);
if ($ret == 0) {
$vmLogger->err($VM_LANG->_('VM_UPDATE_ERR_EXTRACT_FAILED') . " " . $extractdir . ' (' . $zipfile->errorName(true) . ')');
return false;
}
break;
default:
$vmLogger->err('An invalid patch package extension was detected. Allowed Types: tar.gz and zip');
return false;
}
}
}
$fileArr = array();
$queryArr = array();
$result = true;
// Can we use the PHP5 SimpleXML Extension ?
if (function_exists('simplexml_load_file')) {
$xml = @simplexml_load_file($update_manifest);
if ($xml === false) {
$vmLogger->err($VM_LANG->_('VM_UPDATE_ERR_PARSE_FAILED'));
return false;
}
$toversion = (string) $xml->toversion;
$forversion = (string) $xml->forversion;
$description = (string) $xml->description;
$releasedate = (string) $xml->releasedate;
foreach ($xml->files->file as $file) {
if (file_exists($extractdir . '/' . $file)) {
$fileArr[] = array('filename' => (string) $file, 'copy_policy' => (string) @$file['copy']);
} else {
$vmLogger->err(sprintf($VM_LANG->_('VM_UPDATE_ERR_FILE_MISSING'), $file));
$result = false;
}
}
if ($result === false) {
return $result;
}
if (!empty($xml->queries->query)) {
foreach ($xml->queries->query as $query) {
$queryArr[] = (string) $query;
}
}
// RickG - Look for an install file
$installfile = (string) $xml->vminstallfile;
if ($installfile) {
if (file_exists($extractdir . DS . $installfile)) {
$returnArr['installfile'] = $extractdir . DS . $installfile;
} else {
$returnArr['installfile'] = '';
}
}
} else {
// Use the SimpleXML Equivalent
require_once CLASSPATH . 'simplexml.php';
$xml = new vmSimpleXML();
$result = $xml->loadFile($update_manifest);
if ($result === false) {
$vmLogger->err($VM_LANG->_('VM_UPDATE_ERR_PARSE_FAILED'));
return false;
}
$result = true;
$xml = $xml->document;
$toversion = $xml->toversion[0]->data();
$forversion = $xml->forversion[0]->data();
$description = $xml->description[0]->data();
$releasedate = $xml->releasedate[0]->data();
foreach ($xml->files[0]->file as $file) {
if (file_exists($extractdir . '/' . $file->data())) {
//.........这里部分代码省略.........
示例9: chargeur_charger_zip
function chargeur_charger_zip($quoi = array())
{
if (!$quoi) {
return true;
}
if (is_scalar($quoi)) {
$quoi = array('zip' => $quoi);
}
if (isset($quoi['depot']) || isset($quoi['nom'])) {
$quoi['zip'] = $quoi['depot'] . $quoi['nom'] . '.zip';
}
foreach (array( 'remove' => 'spip',
'arg' => 'lib',
'plugin' => null,
'cache_cache' => null,
'rename' => array(),
'edit' => array(),
'root_extract' => false, # extraire a la racine de dest ?
'tmp' => sous_repertoire(_DIR_CACHE, 'chargeur')
)
as $opt=>$def) {
isset($quoi[$opt]) || ($quoi[$opt] = $def);
}
# destination finale des fichiers
switch($quoi['arg']) {
case 'lib':
$quoi['dest'] = _DIR_RACINE.'lib/';
break;
case 'plugins':
$quoi['dest'] = _DIR_PLUGINS_AUTO;
break;
default:
$quoi['dest'] = '';
break;
}
if (!@file_exists($fichier = $quoi['fichier']))
return 0;
include_spip('inc/pclzip');
$zip = new PclZip($fichier);
$list = $zip->listContent();
// on cherche la plus longue racine commune a tous les fichiers
$max_n = 999999;
foreach($list as $n) {
$p = array();
foreach(explode('/', $n['filename']) as $n => $x) {
if ($n>$max_n)
continue;
$sofar = join('/',$p);
$paths[$n][$sofar]++;
$p[] = $x;
}
$max_n = min($n,$max_n);
}
$total = $paths[0][''];
$i = 0;
while (isset($paths[$i])
AND count($paths[$i]) <= 1
AND array_values($paths[$i]) == array($total))
$i++;
$racine = '';
if ($i){
$racine = array_keys($paths[$i-1]);
$racine = array_pop($racine).'/';
}
$quoi['remove'] = $racine;
if (!strlen($nom = basename($racine)))
$nom = basename($fichier, '.zip');
$dir_export = $quoi['root_extract']
? $quoi['dest']
: $quoi['dest'] . $nom.'/';
$tmpname = $quoi['tmp'].$nom.'/';
// On extrait, mais dans tmp/ si on ne veut pas vraiment le faire
$ok = $zip->extract(
PCLZIP_OPT_PATH,
$quoi['extract']
? $dir_export
: $tmpname
,
PCLZIP_OPT_SET_CHMOD, _SPIP_CHMOD,
PCLZIP_OPT_REPLACE_NEWER,
PCLZIP_OPT_REMOVE_PATH, $quoi['remove']
);
if ($zip->error_code < 0) {
spip_log('charger_decompresser erreur zip ' . $zip->error_code .
' pour paquet: ' . $quoi['zip']);
return //$zip->error_code
$zip->errorName(true);
//.........这里部分代码省略.........
示例10: extractArchive
/**
* Extracts the package archive file
* @return boolean True on success, False on error
*/
function extractArchive($filename)
{
$mosConfig_absolute_path = mamboCore::get('mosConfig_absolute_path');
$base_Dir = mosPathName($mosConfig_absolute_path . '/media');
$this->archiveName = $base_Dir . $filename;
$tmpdir = uniqid('install_');
$this->extractDir = $this->cleanDir = mosPathName($base_Dir . uniqid('install_'));
if (eregi('.zip$', $filename)) {
// Extract functions
require_once $mosConfig_absolute_path . '/administrator/includes/pcl/pclzip.lib.php';
require_once $mosConfig_absolute_path . '/administrator/includes/pcl/pclerror.lib.php';
//require_once( $mosConfig_absolute_path . '/administrator/includes/pcl/pcltrace.lib.php' );
//require_once( $mosConfig_absolute_path . '/administrator/includes/pcl/pcltar.lib.php' );
$zipfile = new PclZip($this->archiveName);
$ret = $zipfile->extract(PCLZIP_OPT_PATH, $this->extractDir);
if ($ret == 0) {
$this->errors->addErrorDetails(sprintf(T_('Installer unrecoverable ZIP error %s in %s'), $zipfile->errorName(true), $this->archiveName), _MOS_ERROR_FATAL);
return false;
}
} else {
require_once $mosConfig_absolute_path . '/includes/Archive/Tar.php';
$archive =& new Archive_Tar($this->archiveName);
$archive->setErrorHandling(PEAR_ERROR_PRINT);
if (!$archive->extractModify($this->extractDir, '')) {
$this->errors->addErrorDetails(sprintf(T_('Installer unrecoverable TAR error in %s'), $this->archiveName), _MOS_ERROR_FATAL);
return false;
}
}
// Try to find the correct install dir. in case that the package have subdirs
// Save the install dir for later cleanup
$dir =& new mosDirectory($this->extractDir);
$singledir = $dir->soleDir();
if ($singledir) {
$this->extractDir = mosPathName($this->extractDir . $singledir);
}
return true;
}
示例11: teleporter_http_charger_zip
/**
* Charger un zip à partir d'un tableau d'options descriptives
*
* @uses http_deballe_recherche_racine()
*
* @param array $quoi
* Tableau d'options
* @return array|bool|int|string
* En cas de réussite, Tableau décrivant le zip, avec les index suivant :
* - files : la liste des fichiers présents dans le zip,
* - size : la taille décompressée
* - compressed_size : la taille compressée
* - dirname : répertoire où les fichiers devront être décompréssés
* - tmpname : répertoire temporaire où les fichiers sont décompressés
* - target : cible sur laquelle décompresser les fichiers...
*/
function teleporter_http_charger_zip($quoi = array())
{
if (!$quoi) {
return false;
}
foreach (array('remove' => 'spip', 'rename' => array(), 'edit' => array(), 'root_extract' => false, 'tmp' => sous_repertoire(_DIR_CACHE, 'chargeur')) as $opt => $def) {
isset($quoi[$opt]) || ($quoi[$opt] = $def);
}
if (!@file_exists($fichier = $quoi['fichier'])) {
return 0;
}
include_spip('inc/pclzip');
$zip = new PclZip($fichier);
$list = $zip->listContent();
$racine = http_deballe_recherche_racine($list);
$quoi['remove'] = $racine;
// si pas de racine commune, reprendre le nom du fichier zip
// en lui enlevant la racine h+md5 qui le prefixe eventuellement
// cf action/charger_plugin L74
if (!strlen($nom = basename($racine))) {
$nom = preg_replace(",^h[0-9a-f]{8}-,i", "", basename($fichier, '.zip'));
}
$dir_export = $quoi['root_extract'] ? $quoi['dest'] : $quoi['dest'] . $nom;
$dir_export = rtrim($dir_export, '/') . '/';
$tmpname = $quoi['tmp'] . $nom . '/';
// choisir la cible selon si on veut vraiment extraire ou pas
$target = $quoi['extract'] ? $dir_export : $tmpname;
// ici, il faut vider le rep cible si il existe deja, non ?
if (is_dir($target)) {
supprimer_repertoire($target);
}
// et enfin on extrait
$ok = $zip->extract(PCLZIP_OPT_PATH, $target, PCLZIP_OPT_SET_CHMOD, _SPIP_CHMOD, PCLZIP_OPT_REPLACE_NEWER, PCLZIP_OPT_REMOVE_PATH, $quoi['remove']);
if ($zip->error_code < 0) {
spip_log('charger_decompresser erreur zip ' . $zip->error_code . ' pour paquet: ' . $quoi['archive'], "teleport" . _LOG_ERREUR);
return $zip->errorName(true);
}
spip_log('charger_decompresser OK pour paquet: ' . $quoi['archive'], "teleport");
$size = $compressed_size = 0;
$removex = ',^' . preg_quote($quoi['remove'], ',') . ',';
foreach ($list as $a => $f) {
$size += $f['size'];
$compressed_size += $f['compressed_size'];
$list[$a] = preg_replace($removex, '', $f['filename']);
}
// Indiquer par un fichier install.log
// a la racine que c'est chargeur qui a installe ce plugin
ecrire_fichier($target . 'install.log', "installation: charger_plugin\n" . "date: " . gmdate('Y-m-d\\TH:i:s\\Z', time()) . "\n" . "source: " . $quoi['archive'] . "\n");
return array('files' => $list, 'size' => $size, 'compressed_size' => $compressed_size, 'dirname' => $dir_export, 'tmpname' => $tmpname, 'target' => $target);
}
示例12: array
function upload_save($redirect = true)
{
global $my, $mainframe, $database, $option, $priTask, $subTask;
global $WBG_CONFIG, $wbGalleryDB_cat, $wbGallery_common, $wbGallery_eng;
// Prepare Runtime
$tempDir = null;
$known_images = array('image/pjpeg', 'image/jpeg', 'image/jpg', 'image/png', 'image/gif');
$time = time();
// Importing
$importFolder = mosGetParam($_REQUEST, 'folder', '');
if ($importFolder && !file_exists($importFolder)) {
echo "<script> alert('Import Folder Does Not Exist'); document.location.href='index2.php?option=" . $option . "&task=image.upload'; </script>\n";
exit;
}
// Default Values
$defRow = new wbGalleryDB_img($database);
$defRow->bind($_POST);
// Debug
echo "Image Processing Start: " . $time . '<br/>';
// ==============================v========================================
// Single File Upload
if (!empty($_FILES['img']['tmp_name'])) {
// Debug
echo "Single File Detected <br/>";
if (!in_array($_FILES['img']['type'], $known_images)) {
echo "<script> alert('Image type: " . $_FILES['img']['type'] . " is an unknown type'); document.location.href='index2.php?option=" . $option . "&task=image.upload'; </script>\n";
exit;
}
$wbGallery_eng->add($_FILES['img']['tmp_name'], $_FILES['img']['name'], $_FILES['img']['type'], $defRow);
if ($redirect) {
mosRedirect('index2.php?option=' . $option . '&task=image.upload', 'Image Saved');
}
}
// ==============================v========================================
// Zip File Upload
if (!empty($_FILES['zip']['tmp_name'])) {
//zip file upload
// Debug
echo "Compressed File Uploaded <br/>";
// Create / Define Temporary Folder for Unzipped Files
if (!mkdir($mainframe->getCfg('absolute_path') . '/media/' . $time)) {
if (!mkdir('/tmp/' . $time)) {
echo "<script> alert('Unable to Create Temp Directory'); history.back(); </script>\n";
exit;
} else {
$tempDir = '/tmp/' . $time;
}
} else {
$tempDir = $mainframe->getCfg('absolute_path') . '/media/' . $time;
}
// Uncompress ZIP or TAR.GZ
if (preg_match('/zip$/i', $_FILES['zip']['name'])) {
// Load ZIP functions
require_once $mainframe->getCfg('absolute_path') . '/administrator/includes/pcl/pclzip.lib.php';
require_once $mainframe->getCfg('absolute_path') . '/administrator/includes/pcl/pclerror.lib.php';
$zipfile = new PclZip($_FILES['zip']['tmp_name']);
if (substr(PHP_OS, 0, 3) == 'WIN') {
define('OS_WINDOWS', 1);
} else {
define('OS_WINDOWS', 0);
}
$ret = $zipfile->extract(PCLZIP_OPT_PATH, $tempDir);
if ($ret == 0) {
$wbGallery_common->remove_dir($tempDir);
echo "<script> alert('ZIP Extraction Error: " . $zipfile->errorName(true) . "'); history.back(); </script>\n";
exit;
}
} elseif (preg_match('/tar.gz$/i', $_FILES['zip']['name'])) {
// Load TAR functions
require_once $mainframe->getCfg('absolute_path') . '/includes/Archive/Tar.php';
$archive = new Archive_Tar($_FILES['zip']['tmp_name']);
$archive->setErrorHandling(PEAR_ERROR_PRINT);
if (!$archive->extractModify($tempDir, '')) {
$wbGallery_common->remove_dir($tempDir);
echo "<script> alert('TAR Extraction Error'); history.back(); </script>\n";
exit;
}
} else {
// Unknown File...
$wbGallery_common->remove_dir($tempDir);
echo "<script> alert('Unknown File Format - Must be .ZIP or .TAR.GZ'); history.back(); </script>\n";
exit;
}
}
// Zip File Upload
// ==============================v========================================
// Process Files from Folder
if ($tempDir || $importFolder) {
$processDirs = array();
$files_added = 0;
$files_skipped = 0;
if ($tempDir) {
$processDirs[] = array('path' => $tempDir, 'remove' => 1);
}
if ($importFolder) {
$processDirs[] = array('path' => $importFolder, 'remove' => 0);
}
if (count($processDirs)) {
foreach ($processDirs as $procDir) {
// Read Files from Temp Folder
//.........这里部分代码省略.........
示例13: themeUpload
function themeUpload()
{
if (!$_POST['ac'] == md5(ADMINPWCHANGE)) {
exit;
}
$mes = e107::getMessage();
$ns = e107::getRender();
extract($_FILES);
if (!is_writable(e_THEME)) {
// $ns->tablerender(TPVLAN_16, TPVLAN_20);
$mes->add(TPVLAN_20, E_MESSAGE_INFO);
return FALSE;
} else {
require_once e_HANDLER . "upload_handler.php";
$fileName = $file_userfile['name'][0];
$fileSize = $file_userfile['size'][0];
$fileType = $file_userfile['type'][0];
if (strstr($file_userfile['type'][0], "gzip")) {
$fileType = "tar";
} else {
if (strstr($file_userfile['type'][0], "zip")) {
$fileType = "zip";
} else {
$mes->add(TPVLAN_17, E_MESSAGE_ERROR);
// $ns->tablerender(TPVLAN_16, TPVLAN_17);
// require_once("footer.php");
return FALSE;
}
}
if ($fileSize) {
$uploaded = file_upload(e_THEME);
$archiveName = $uploaded[0]['name'];
if ($fileType == "zip") {
require_once e_HANDLER . "pclzip.lib.php";
$archive = new PclZip(e_THEME . $archiveName);
$unarc = $fileList = $archive->extract(PCLZIP_OPT_PATH, e_THEME, PCLZIP_OPT_SET_CHMOD, 0666);
} else {
require_once e_HANDLER . "pcltar.lib.php";
$unarc = $fileList = PclTarExtract($archiveName, e_THEME);
}
if (!$unarc) {
if ($fileType == "zip") {
$error = TPVLAN_46 . " '" . $archive->errorName(TRUE) . "'";
} else {
$error = TPVLAN_47 . PclErrorString() . ", " . TPVLAN_48 . intval(PclErrorCode());
}
$mes->add(TPVLAN_18 . " " . $archiveName . " " . $error, E_MESSAGE_ERROR);
// $ns->tablerender(TPVLAN_16, TPVLAN_18." ".$archiveName." ".$error);
return FALSE;
}
$folderName = substr($fileList[0]['stored_filename'], 0, strpos($fileList[0]['stored_filename'], "/"));
$mes->add(TPVLAN_19, E_MESSAGE_SUCCESS);
if (varset($_POST['setUploadTheme'])) {
$themeArray = $this->getThemes();
$this->id = $themeArray[$folderName]['id'];
$this->setTheme();
}
// $ns->tablerender(TPVLAN_16, "<div class='center'>".TPVLAN_19."</div>");
@unlink(e_THEME . $archiveName);
}
}
}
示例14: extractArchive
/**
* Extracts the package archive file
* @return boolean True on success, False on error
*/
function extractArchive()
{
global $_CB_framework;
$base_Dir = _cbPathName($_CB_framework->getCfg('tmp_path'));
$archivename = $this->installArchive();
$tmpdir = uniqid('install_');
$extractdir = _cbPathName($base_Dir . $tmpdir);
$archivename = _cbPathName($archivename, false);
$this->unpackDir($extractdir);
if (preg_match("/\\.zip\$/i", $archivename)) {
// Extract functions
cbimport('pcl.pclziplib');
$zipfile = new PclZip($archivename);
if ($this->isWindows()) {
define('OS_WINDOWS', 1);
} else {
define('OS_WINDOWS', 0);
}
$ret = $zipfile->extract(PCLZIP_OPT_PATH, $extractdir);
if ($ret == 0) {
$this->setError(1, 'Unrecoverable error "' . $zipfile->errorName(true) . '"');
return false;
}
} else {
cbimport('pcl.tar');
// includes/Archive/Tar.php' );
$archive = new Archive_Tar($archivename);
$archive->setErrorHandling(PEAR_ERROR_PRINT);
if (!$archive->extractModify($extractdir, '')) {
$this->setError(1, 'Extract Error');
return false;
}
}
$this->installDir($extractdir);
// Try to find the correct install dir. in case that the package have subdirs
// Save the install dir for later cleanup
$filesindir = cbReadDirectory($this->installDir(), '');
if (count($filesindir) == 1) {
if (is_dir($extractdir . $filesindir[0])) {
$this->installDir(_cbPathName($extractdir . $filesindir[0]));
}
}
return true;
}
示例15: action_odt2spip_importe
function action_odt2spip_importe() {
global $visiteur_session;
$id_auteur = $visiteur_session['id_auteur'];
$arg = _request('arg');
$args = explode(":",$arg);
// le 1er element de _request('arg') est id_rubrique=XXX
$Targs = explode("=", $args[0]);
$id_rubrique = $Targs[1];
$hash = _request('hash');
$redirect = _request('redirect');
if ($redirect==NULL) $redirect="";
include_spip("inc/securiser_action");
if (!autoriser('creerarticledans', 'rubrique', $id_rubrique)) die(_T('avis_non_acces_page'));
// ss-rep temporaire specifique de l'auteur en cours: tmp/odt2spip/id_auteur/ => le creer si il n'existe pas
$base_dezip = _DIR_TMP."odt2spip/"; // avec / final
if (!is_dir($base_dezip)) if (!sous_repertoire(_DIR_TMP,'odt2spip')) die (_T('odtspip:err_repertoire_tmp'));
$rep_dezip = $base_dezip.$id_auteur.'/';
if (!is_dir($rep_dezip)) if (!sous_repertoire($base_dezip,$id_auteur)) die (_T('odtspip:err_repertoire_tmp'));
// traitement d'un fichier odt envoye par $_POST
$fichier_zip = addslashes($_FILES['fichier_odt']['name']);
if ($_FILES['fichier_odt']['name'] == ''
OR $_FILES['fichier_odt']['error'] != 0
OR !move_uploaded_file($_FILES['fichier_odt']['tmp_name'], $rep_dezip.$fichier_zip)
) die(_T('odtspip:err_telechargement_fichier'));
// dezipper le fichier odt a la mode SPIP
include_spip("inc/pclzip");
$zip = new PclZip($rep_dezip.$fichier_zip);
$ok = $zip->extract(
PCLZIP_OPT_PATH, $rep_dezip,
PCLZIP_OPT_SET_CHMOD, _SPIP_CHMOD,
PCLZIP_OPT_REPLACE_NEWER
);
if ($zip->error_code < 0) {
spip_log('charger_decompresser erreur zip ' . $zip->error_code .' pour fichier ' . $rep_dezip.$fichier_zip);
die($zip->errorName(true)); //$zip->error_code
}
// Creation du fichier necessaire a snippets
$odt2spip_generer_sortie = charger_fonction('odt2spip_generer_sortie','inc');
list($fichier_sortie,$xml_sortie) = $odt2spip_generer_sortie($id_auteur,$rep_dezip);
// generer l'article a partir du fichier xml de sortie (code pompe sur plugins/snippets/action/snippet_importe.php)
include_spip('inc/snippets');
$table = $id = 'articles';
$contexte = $args[0];
$source = $fichier_sortie;
if (!$f = snippets_fonction_importer($table)) die(_T('odtspip:err_import_snippet'));
include_spip('inc/xml');
$arbre = spip_xml_load($source, false);
$translations = $f($id,$arbre,$contexte);
snippets_translate_raccourcis_modeles($translations);
$id_article = $translations[0][2];
// si on est en 2.0 passer le statut de l'article en prepa
sql_updateq('spip_articles', array('statut' => 'prop'), 'id_article='.$id_article);
// si necessaire attacher le fichier odt original a l'article et lui mettre un titre signifiant
if (_request('attacher_odt') == '1') {
// recuperer le titre
preg_match('/<titre>(.*?)<\/titre>/', $xml_sortie, $match);
$titre = $match[1];
if (!isset($ajouter_documents))
$ajouter_documents = charger_fonction('ajouter_documents','inc');
// la y'a un bogue super-bizarre avec la fonction spip_abstract_insert() qui est donnee comme absente lors de l'appel de ajouter_document()
if (!function_exists('spip_abstract_insert')) include_spip('base/abstract_sql');
$id_doc_odt = $ajouter_documents($rep_dezip.$fichier_zip, $fichier_zip, "article", $id_article, 'document', 0, $toto='');
$c = array(
'titre' => $titre,
'descriptif' => _T('odtspip:cet_article_version_odt')
);
include_spip('inc/modifier');
revision_document($id_doc_odt,$c);
}
if (!function_exists('effacer_repertoire_temporaire')) include_spip('inc/getdocument');
// vider le contenu du rep de dezippage
effacer_repertoire_temporaire($rep_dezip);
// aller sur la page de l'article qui vient d'etre cree
redirige_par_entete(parametre_url(str_replace("&","&",urldecode($redirect)),'id_article',$id_article,'&'));
}