本文整理汇总了PHP中nggAdmin::unzip方法的典型用法代码示例。如果您正苦于以下问题:PHP nggAdmin::unzip方法的具体用法?PHP nggAdmin::unzip怎么用?PHP nggAdmin::unzip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nggAdmin
的用法示例。
在下文中一共展示了nggAdmin::unzip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import_zipfile
/**
* Import a ZIP file via a upload form or a URL
*
* @class nggAdmin
* @param int (optional) $galleryID
* @return bool $result
*/
function import_zipfile($galleryID)
{
global $ngg, $wpdb;
if (nggWPMU::check_quota()) {
return false;
}
$defaultpath = $ngg->options['gallerypath'];
$zipurl = $_POST['zipurl'];
// if someone entered a URL try to upload it
if (!empty($zipurl) && function_exists('curl_init')) {
if (!preg_match('/^http(s)?:\\/\\//i', $zipurl)) {
nggGallery::show_error(__('No valid URL path ', 'nggallery'));
return false;
}
$temp_zipfile = tempnam('/tmp', 'zipimport_');
$filename = basename($zipurl);
//Grab the zip via cURL
$save = fopen($temp_zipfile, "w");
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $save);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $zipurl);
$success = curl_exec($ch);
if (!$success) {
nggGallery::show_error(__('Import via cURL failed.', 'nggallery') . ' Error code ' . curl_errno($ch) . ' : ' . curl_error($ch));
}
curl_close($ch);
fclose($save);
if (!$success) {
return false;
}
} else {
$temp_zipfile = $_FILES['zipfile']['tmp_name'];
$filename = $_FILES['zipfile']['name'];
// Chrome return a empty content-type : http://code.google.com/p/chromium/issues/detail?id=6800
if (!preg_match('/chrome/i', $_SERVER['HTTP_USER_AGENT'])) {
// check if file is a zip file
if (!preg_match('/(zip|download|octet-stream)/i', $_FILES['zipfile']['type'])) {
@unlink($temp_zipfile);
// del temp file
nggGallery::show_error(__('Uploaded file was no or a faulty zip file ! The server recognized : ', 'nggallery') . $_FILES['zipfile']['type']);
return false;
}
}
}
// should this unpacked into a new folder ?
if ($galleryID == '0') {
//cleanup and take the zipfile name as folder name
$foldername = sanitize_title(strtok($filename, '.'));
$foldername = $defaultpath . $foldername;
} else {
// get foldername if selected
$foldername = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$galleryID}' ");
}
if (empty($foldername)) {
nggGallery::show_error(__('Could not get a valid foldername', 'nggallery'));
return false;
}
// set complete folder path
$newfolder = WINABSPATH . $foldername;
// check first if the traget folder exist
if (!is_dir($newfolder)) {
// create new directories
if (!wp_mkdir_p($newfolder)) {
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'nggallery'), $newfolder);
nggGallery::show_error($message);
return false;
}
if (!wp_mkdir_p($newfolder . '/thumbs')) {
nggGallery::show_error(__('Unable to create directory ', 'nggallery') . $newfolder . '/thumbs !');
return false;
}
}
// unzip and del temp file
$result = nggAdmin::unzip($newfolder, $temp_zipfile);
@unlink($temp_zipfile);
if ($result) {
$message = __('Zip-File successfully unpacked', 'nggallery') . '<br />';
// parse now the folder and add to database
$message .= nggAdmin::import_gallery($foldername);
nggGallery::show_message($message);
}
return true;
}
示例2: import_zipfile
function import_zipfile($galleryID)
{
global $ngg, $wpdb;
if (nggAdmin::check_quota()) {
return false;
}
$defaultpath = $ngg->options['gallerypath'];
$temp_zipfile = $_FILES['zipfile']['tmp_name'];
$filename = $_FILES['zipfile']['name'];
// check if file is a zip file
if (!eregi('zip|download|octet-stream', $_FILES['zipfile']['type'])) {
@unlink($temp_zipfile);
// del temp file
nggGallery::show_error(__('Uploaded file was no or a faulty zip file ! The server recognize : ', 'nggallery') . $_FILES['zipfile']['type']);
return false;
}
// should this unpacked into a new folder ?
if ($galleryID == '0') {
//cleanup and take the zipfile name as folder name
$foldername = sanitize_title(strtok($filename, '.'));
$foldername = $defaultpath . $foldername;
} else {
// get foldername if selected
$foldername = $wpdb->get_var("SELECT path FROM {$wpdb->nggallery} WHERE gid = '{$galleryID}' ");
}
if (empty($foldername)) {
nggGallery::show_error(__('Could not get a valid foldername', 'nggallery'));
return false;
}
// set complete folder path
$newfolder = WINABSPATH . $foldername;
// check first if the traget folder exist
if (!is_dir($newfolder)) {
// create new directories
if (!wp_mkdir_p($newfolder)) {
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?', 'nggallery'), $newfolder);
nggGallery::show_error($message);
return false;
}
if (!wp_mkdir_p($newfolder . '/thumbs')) {
nggGallery::show_error(__('Unable to create directory ', 'nggallery') . $newfolder . '/thumbs !');
return false;
}
}
// unzip and del temp file
$result = nggAdmin::unzip($newfolder, $temp_zipfile);
@unlink($temp_zipfile);
if ($result) {
$message = __('Zip-File successfully unpacked', 'nggallery') . '<br />';
// parse now the folder and add to database
$message .= nggAdmin::import_gallery($foldername);
nggGallery::show_message($message);
}
return true;
}