本文整理汇总了PHP中ZipArchive::deleteIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP ZipArchive::deleteIndex方法的具体用法?PHP ZipArchive::deleteIndex怎么用?PHP ZipArchive::deleteIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipArchive
的用法示例。
在下文中一共展示了ZipArchive::deleteIndex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeThumbs
public static function removeThumbs($filename)
{
if (!file_exists($filename)) {
return false;
}
$za = new \ZipArchive();
$za->open($filename);
$count = 0;
for ($i = 0; $i < $za->numFiles; $i++) {
$stat = $za->statIndex($i);
if (basename($stat['name']) !== 'Thumbs.db') {
continue;
}
$za->deleteIndex($i);
$count++;
}
$za->close();
return $count;
}
示例2: isCorrectFormat
private function isCorrectFormat($file)
{
if (class_exists('ZipArchive')) {
$success = false;
$zip = new ZipArchive();
if ($zip->open($file) === true) {
for ($i = 0; $i < $zip->numFiles; ++$i) {
$filename = $zip->getNameIndex($i);
if (substr($filename, 0, strlen($this->addonkey . '/')) != $this->addonkey . '/') {
$zip->deleteIndex($i);
} else {
$success = true;
}
}
$zip->close();
}
return $success;
}
return file_exists("phar://{$file}/" . $this->addonkey);
}
示例3: ZipArchive
<?php
/**
* Created by PhpStorm.
* User: sergey
* Date: 15.11.15
* Time: 14:02
*/
$sourcefile = 'flowers_odtTemplate.odt';
$xslt = 'flowers_odt.xslt';
$zip = new ZipArchive();
$zip->open($sourcefile);
$content = $zip->getFromName('content.xml');
if (file_put_contents($xslt, $content)) {
echo 'Main content extracted<br>';
} else {
echo 'Problem extracting main content';
}
for ($i = 0; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
if (pathinfo($filename, PATHINFO_DIRNAME) == 'Pictures') {
if ($zip->deleteIndex($i)) {
echo 'Image deleted<br>';
} else {
echo 'Problem deleting image<br>';
}
}
}
$zip->close();
示例4: execute
public function execute()
{
global $I18N;
$this->addonkey = rex_request('addonkey', 'string');
$function = static::GET_PACKAGES_FUNCTION;
$packages = rex_install_packages::$function();
$this->fileId = rex_request('file', 'int');
if (!isset($packages[$this->addonkey]['files'][$this->fileId])) {
return null;
}
$this->file = $packages[$this->addonkey]['files'][$this->fileId];
$this->checkPreConditions();
$archivefile = rex_install_webservice::getArchive($this->file['path']);
$message = '';
$this->archive = $archivefile;
if (class_exists("ZipArchive")) {
$success = false;
$zip = new ZipArchive();
if ($zip->open($archivefile) === TRUE) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
if (substr($filename, 0, strlen($this->addonkey . '/')) != $this->addonkey . '/') {
$zip->deleteIndex($i);
} else {
$success = true;
}
}
$zip->close();
}
if (!$success) {
$message = $I18N->msg('install_warning_zip_wrong_format');
}
} else {
if (!file_exists("phar://{$archivefile}/" . $this->addonkey)) {
$message = $I18N->msg('install_warning_zip_wrong_format');
}
}
if ($message != "") {
} else {
if ($this->file['checksum'] != md5_file($archivefile)) {
$message = $I18N->msg('install_warning_zip_wrong_checksum');
} else {
if (is_string($msg = $this->doAction())) {
$message = $msg;
}
}
}
rex_file::delete($archivefile);
if ($message) {
$message = $I18N->msg('install_warning_addon_not_' . static::VERB, $this->addonkey) . '<br />' . $message;
$success = false;
} else {
$message = $I18N->msg('install_info_addon_' . static::VERB, $this->addonkey) . (static::SHOW_LINK ? ' <a href="index.php?page=addon">' . $I18N->msg('install_to_addon_page') . '</a>' : '');
$success = true;
unset($_REQUEST['addonkey']);
}
if ($success) {
return $message;
} else {
throw new rex_install_functional_exception($message);
}
}
示例5: ZipArchive
if ($uploadfilename) {
// Check ZIP file contents for extra directory at the top
$za = new ZipArchive();
$za->open($uploadfilename);
for ($i = 0; $i < $za->numFiles; $i++) {
$entryName = $za->getNameIndex($i);
$firstSlash = strpos($entryName, '/');
if ($entryName === 'manifest.xml' || $entryName === './manifest.xml' || $firstSlash === false) {
$za->unchangeAll();
break;
}
$newEntryName = substr($entryName, $firstSlash + 1);
if ($newEntryName !== false) {
$za->renameIndex($i, $newEntryName);
} else {
$za->deleteIndex($i);
}
}
$za->close();
$package = new Vtiger_Package();
$moduleimport_name = $package->getModuleNameFromZip($uploadfilename);
if ($moduleimport_name == null) {
$smarty->assign("MODULEIMPORT_FAILED", "true");
$smarty->assign("MODULEIMPORT_FILE_INVALID", "true");
} else {
if (!$package->isLanguageType() && !$package->isModuleBundle()) {
$moduleInstance = Vtiger_Module::getInstance($moduleimport_name);
$moduleimport_exists = $moduleInstance ? "true" : "false";
$moduleimport_dir_name = "modules/{$moduleimport_name}";
$moduleimport_dir_exists = is_dir($moduleimport_dir_name) ? "true" : "false";
$smarty->assign("MODULEIMPORT_EXISTS", $moduleimport_exists);
示例6: dirname
<?php
$dirname = dirname(__FILE__) . '/';
$arch = new ZipArchive();
$arch->open($dirname . 'foo.zip', ZIPARCHIVE::CREATE);
var_dump($arch->getStatusString());
//delete an index that does not exist - trigger error
$arch->deleteIndex(2);
var_dump($arch->getStatusString());
$arch->close();
unlink($dirname . 'foo.zip');
示例7: ZipArchive
function _rename_zip_path($file, $original_path, $replacement_path)
{
$original_path = preg_replace('|^[/\\\\]+|', '', $original_path);
$original_path = preg_replace('|([/\\\\])+$|', '', $original_path);
$original_path .= '/';
$replacement_path = preg_replace('|^[/\\\\]+|', '', $replacement_path);
$replacement_path = preg_replace('|[/\\\\]+$|', '', $replacement_path);
if (!empty($replacement_path)) {
$replacement_path .= '/';
}
$zip = new ZipArchive();
echo $file;
$open_status = $zip->open($file);
if (true !== $open_status) {
// return array( 'error' => $this->get_zip_archive_error_message( $open_status ) );
return array('error' => 'Unable to rename path');
}
$status = array('removed' => 0, 'renamed' => 0);
for ($index = 0; $index < $zip->numFiles; $index++) {
$name = $zip->getNameIndex($index);
if ($name === $original_path) {
// Remove original container directory
$zip->deleteIndex($index);
$status['removed']++;
} else {
if (preg_match('/^' . preg_quote($original_path, '/') . '(.+)/', $name, $matches)) {
// Rename paths
$zip->renameIndex($index, "{$replacement_path}{$matches[1]}");
$status['renamed']++;
}
}
}
$zip->close();
return $status;
}
示例8: getFirmwareAction
//.........这里部分代码省略.........
//echo $params['firmware'];
$result['fname'] = explode(" ", $params['firmware']);
foreach ($data as $val) {
$val['optionDisplay'] = explode(" ", $val['optionDisplay']);
//echo $val['optionDisplay'][0];
if ($val['optionDisplay'][2] == 9) {
}
// echo $result['fname'][0];
if ($result['fname'][1] == 9) {
if (strtoupper($val['optionDisplay'][0]) == strtoupper($result['fname'][0]) and $val['optionDisplay'][2] == 9) {
// echo 1;
$params['version'] = $val['optionValue'];
}
} else {
if (strtoupper($val['optionDisplay'][0]) == strtoupper($result['fname'][0]) and $val['optionDisplay'][2] != 9) {
// echo 1;
$params['version'] = $val['optionValue'];
}
}
}
if (!isset($params['serial']) or empty($params['serial'])) {
$params['serial'] = $params['crum'];
}
$postdata = "generate=1&manufacturer={$params['vendor']}&model={$params['model']}&version={$params['version']}&serial={$params['serial']}&crum={$params['crum']}&type={$types[$params['type']]}";
/// echo $postdata;
// exit();
$url1 = "http://www.korotron-online.net/Firmware";
$reffer = "http://www.korotron-online.net/Firmware";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_REFERER, $reffer);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_COOKIE, $cookies);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$data = curl_exec($curl);
curl_close($curl);
// echo $data;
preg_match_all('|Location: (.*)|', $data, $matches);
list($header, $body) = explode("\r\n\r\n", $data, 2);
// print_r($matches);
//echo $matches[1][0];
$m = htmlspecialchars(trim($matches[1][0]));
$m = explode("\r", $matches[1][0]);
$postdata = '';
//exit();
//открываем файловый дескриптор (куда сохранять файл)
$fp = fopen($filename . '.zip', 'w+b');
$idDown = explode("/", $matches[1][0]);
$idDown[3] = trim($idDown[3]);
$id = $idDown[3];
$url = "http://www.korotron-online.net/Firmware/Download/{$id}/firmware.zip";
//echo $url;
//$reffer = "http://firmware-online.com/Firmware/Redirect/$id";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_REFERER, $reffer);
curl_setopt($curl, CURLOPT_AUTOREFERER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_NOBODY, false);
curl_setopt($curl, CURLOPT_COOKIE, $cookies);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 600);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_FILE, $fp);
$data = curl_exec($curl);
$response = curl_getinfo($curl);
curl_close($curl);
fclose($fp);
//preg_match_all('|Content-Length: (.*)|', $data, $matches);
if (filesize($filename . '.zip') < 100000) {
mysqli_query($this->dbConnect, "update users set summa = summa + {$params['price']} where id = '{$_SESSION['user_id']}'");
mysqli_query($this->dbConnect, "update users set summa = summa + {$params['parrent_price']} where id = '{$params['parrent_id']}'");
exit;
}
//file_put_contents($filename . '.zip', $data, LOCK_EX);
if ($params['modelType'] == 3) {
$zip = new ZipArchive();
if ($zip->open($filename . '.zip') === true) {
$count = $zip->numFiles;
for ($i = 0; $i < $count; $i++) {
$stat = $zip->statIndex($i);
if (strstr($stat['name'], ".txt")) {
$zip->deleteIndex($i);
break;
}
}
$zip->close();
echo 'ok!';
} else {
echo 'ошибка';
}
}
$this->saveResults($params, $filename);
}
示例9: wpcomplete_zipextract
function wpcomplete_zipextract($file, $extractPath)
{
$zip = new ZipArchive();
$res = @$zip->open($file);
if (!@($index = $zip->locateName('.wpcmanifest'))) {
return false;
} else {
if ($res === TRUE) {
//REMOVE THE MANIFEST
@$zip->deleteIndex($index);
//EXTRACT THE ARCHIVE
@$zip->extractTo($extractPath);
//RE-ADD THE MANIFEST
$zip->addFromString('.wpcmanifest', time());
//CLOSE THE ZIP
@$zip->close();
return TRUE;
} else {
return FALSE;
}
}
}
示例10: publish_mixtape_upload
//.........这里部分代码省略.........
mkdir($tapePhotoSlugDir);
file_put_contents($tapePhotoSlugDir . '/index.html', '');
}
//create audio_uploads/user dir
if (!file_exists($userAudioDir)) {
mkdir($userAudioDir);
file_put_contents($userAudioDir . '/index.html', '');
}
//create audio_uploads/user/mixtape dir
if (!file_exists($userTapeDir)) {
mkdir($userTapeDir);
file_put_contents($userTapeDir . '/index.html', '');
}
//create audio_uploads/user/mixtape/tape-slug dir
if (!file_exists($tapePath)) {
mkdir($tapePath);
file_put_contents($tapePath . '/index.html', '');
}
$tape_order = 1;
$p = 1;
//for extra photos
$song_count = 0;
// how many songs are in the zip
for ($i = 0; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
$fullFileName = $zip->statIndex($i);
$ext = substr(strrchr($filename, '.'), 1);
$info = pathinfo($fullFileName['name']);
if ($filename[strlen($filename) - 1] == "/") {
//this is a folder, so do nothing
} else {
if (!in_array($ext, $allowExtensions)) {
//rogue files, delete them from the zip file
$zip->deleteIndex($i);
}
//end rogue
if (in_array($ext, $images)) {
$photoFileName = url_slug($mixtape_title) . '-' . $i;
file_put_contents($tapePhotoSlugDir . '/' . $photoFileName . '.jpg', $zip->getFromIndex($i));
$sizes = array('64', '150', '300', '500');
foreach ($sizes as $size) {
$this->images->resizeImage($tapePhotoSlugDir . '/', $photoFileName, 'jpg', $size);
}
//end foreach
if ($p === 1) {
$extra_image = $photoFileName . '.jpg';
} elseif ($p === 2) {
$extra_image2 = $photoFileName . '.jpg';
}
$p++;
unlink($tapePhotoSlugDir . '/' . $photoFileName . '.jpg');
}
//end images
if (in_array($ext, $songs)) {
$song_file_name = str_replace($this->removePiff, '', $info['filename']);
if (file_put_contents($tapePath . '/' . file_slug($song_file_name) . '.' . $info['extension'], $zip->getFromIndex($i))) {
//write track info to DB
// Get ID3 Infoc
$dir_file = $tapePath . '/' . file_slug($song_file_name) . '.' . $info['extension'];
$tags = $this->tags->getTagsInfo($dir_file);
$temp_title = isset($tags['Title']) ? $tags['Title'] : '';
$temp_artist = isset($tags['Author']) ? $tags['Author'] : '';
$title = str_replace($this->removePiff, '', $temp_title);
$artist = str_replace($this->removePiff, '', $temp_artist);
$data = array('tape_id' => $tape_id, 'user_id' => $this->ion_auth->user()->row()->id, 'song_artist' => $artist, 'song_title' => $title, 'song_url' => url_slug($song_file_name), 'file_name' => $slug . '/' . file_slug($song_file_name) . '.' . $info['extension'], 'can_download' => $can_download, 'tape_order' => $tape_order);
$addTrack = $this->Mixtape_model->add_track($data);