本文整理汇总了PHP中BackWPup_Job::get_mime_type方法的典型用法代码示例。如果您正苦于以下问题:PHP BackWPup_Job::get_mime_type方法的具体用法?PHP BackWPup_Job::get_mime_type怎么用?PHP BackWPup_Job::get_mime_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BackWPup_Job
的用法示例。
在下文中一共展示了BackWPup_Job::get_mime_type方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: job_run_archive
/**
* @param $job_object BAckWPup_Job
* @return bool
*/
public function job_run_archive(BackWPup_Job $job_object)
{
$job_object->substeps_todo = 2 + $job_object->backup_filesize;
if ($job_object->steps_data[$job_object->step_working]['SAVE_STEP_TRY'] != $job_object->steps_data[$job_object->step_working]['STEP_TRY']) {
$job_object->log(sprintf(__('%d. Trying to send backup file to S3 Service …', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']), E_USER_NOTICE);
}
try {
$s3 = Aws\S3\S3Client::factory(array('key' => $job_object->job['s3accesskey'], 'secret' => BackWPup_Encryption::decrypt($job_object->job['s3secretkey']), 'region' => $job_object->job['s3region'], 'base_url' => $this->get_s3_base_url($job_object->job['s3region'], $job_object->job['s3base_url']), 'scheme' => 'https', 'ssl.certificate_authority' => BackWPup::get_plugin_data('cacert')));
if ($job_object->steps_data[$job_object->step_working]['SAVE_STEP_TRY'] != $job_object->steps_data[$job_object->step_working]['STEP_TRY'] && $job_object->substeps_done < $job_object->backup_filesize) {
if ($s3->doesBucketExist($job_object->job['s3bucket'])) {
$bucketregion = $s3->getBucketLocation(array('Bucket' => $job_object->job['s3bucket']));
$job_object->log(sprintf(__('Connected to S3 Bucket "%1$s" in %2$s', 'backwpup'), $job_object->job['s3bucket'], $bucketregion->get('Location')), E_USER_NOTICE);
} else {
$job_object->log(sprintf(__('S3 Bucket "%s" does not exist!', 'backwpup'), $job_object->job['s3bucket']), E_USER_ERROR);
return TRUE;
}
if ($job_object->job['s3multipart'] && empty($job_object->steps_data[$job_object->step_working]['UploadId'])) {
//Check for aboded Multipart Uploads
$job_object->log(__('Checking for not aborted multipart Uploads …', 'backwpup'));
$multipart_uploads = $s3->listMultipartUploads(array('Bucket' => $job_object->job['s3bucket'], 'Prefix' => (string) $job_object->job['s3dir']));
$uploads = $multipart_uploads->get('Uploads');
if (!empty($uploads)) {
foreach ($uploads as $upload) {
$s3->abortMultipartUpload(array('Bucket' => $job_object->job['s3bucket'], 'Key' => $upload['Key'], 'UploadId' => $upload['UploadId']));
$job_object->log(sprintf(__('Upload for %s aborted.', 'backwpup'), $upload['Key']));
}
}
}
//transfer file to S3
$job_object->log(__('Starting upload to S3 Service …', 'backwpup'));
}
if (!$job_object->job['s3multipart'] || $job_object->backup_filesize < 1048576 * 6) {
//Prepare Upload
if (!($up_file_handle = fopen($job_object->backup_folder . $job_object->backup_file, 'rb'))) {
$job_object->log(__('Can not open source file for transfer.', 'backwpup'), E_USER_ERROR);
return FALSE;
}
$create_args = array();
$create_args['Bucket'] = $job_object->job['s3bucket'];
$create_args['ACL'] = 'private';
//encrxption
if (!empty($job_object->job['s3ssencrypt'])) {
$create_args['ServerSideEncryption'] = $job_object->job['s3ssencrypt'];
}
//Storage Class
if (!empty($job_object->job['s3storageclass'])) {
$create_args['StorageClass'] = $job_object->job['s3storageclass'];
}
$create_args['Metadata'] = array('BackupTime' => date('Y-m-d H:i:s', $job_object->start_time));
$create_args['Body'] = $up_file_handle;
$create_args['Key'] = $job_object->job['s3dir'] . $job_object->backup_file;
$create_args['ContentType'] = $job_object->get_mime_type($job_object->backup_folder . $job_object->backup_file);
try {
$s3->putObject($create_args);
} catch (Aws\Common\Exception\MultipartUploadException $e) {
$job_object->log(E_USER_ERROR, sprintf(__('S3 Service API: %s', 'backwpup'), $e->getMessage()), $e->getFile(), $e->getLine());
return FALSE;
}
} else {
//Prepare Upload
if ($file_handle = fopen($job_object->backup_folder . $job_object->backup_file, 'rb')) {
fseek($file_handle, $job_object->substeps_done);
try {
if (empty($job_object->steps_data[$job_object->step_working]['UploadId'])) {
$args = array('ACL' => 'private', 'Bucket' => $job_object->job['s3bucket'], 'ContentType' => $job_object->get_mime_type($job_object->backup_folder . $job_object->backup_file), 'Key' => $job_object->job['s3dir'] . $job_object->backup_file);
if (!empty($job_object->job['s3ssencrypt'])) {
$args['ServerSideEncryption'] = $job_object->job['s3ssencrypt'];
}
if (!empty($job_object->job['s3storageclass'])) {
$args['StorageClass'] = empty($job_object->job['s3storageclass']) ? '' : $job_object->job['s3storageclass'];
}
$upload = $s3->createMultipartUpload($args);
$job_object->steps_data[$job_object->step_working]['UploadId'] = $upload->get('UploadId');
$job_object->steps_data[$job_object->step_working]['Parts'] = array();
$job_object->steps_data[$job_object->step_working]['Part'] = 1;
}
while (!feof($file_handle)) {
$chunk_upload_start = microtime(TRUE);
$part_data = fread($file_handle, 1048576 * 5);
//5MB Minimum part size
$part = $s3->uploadPart(array('Bucket' => $job_object->job['s3bucket'], 'UploadId' => $job_object->steps_data[$job_object->step_working]['UploadId'], 'Key' => $job_object->job['s3dir'] . $job_object->backup_file, 'PartNumber' => $job_object->steps_data[$job_object->step_working]['Part'], 'Body' => $part_data));
$chunk_upload_time = microtime(TRUE) - $chunk_upload_start;
$job_object->substeps_done = $job_object->substeps_done + strlen($part_data);
$job_object->steps_data[$job_object->step_working]['Parts'][] = array('ETag' => $part->get('ETag'), 'PartNumber' => $job_object->steps_data[$job_object->step_working]['Part']);
$job_object->steps_data[$job_object->step_working]['Part']++;
$time_remaining = $job_object->do_restart_time();
if ($time_remaining < $chunk_upload_time) {
$job_object->do_restart_time(TRUE);
}
$job_object->update_working_data();
}
$s3->completeMultipartUpload(array('Bucket' => $job_object->job['s3bucket'], 'UploadId' => $job_object->steps_data[$job_object->step_working]['UploadId'], 'Key' => $job_object->job['s3dir'] . $job_object->backup_file, 'Parts' => $job_object->steps_data[$job_object->step_working]['Parts']));
} catch (Exception $e) {
$job_object->log(E_USER_ERROR, sprintf(__('S3 Service API: %s', 'backwpup'), $e->getMessage()), $e->getFile(), $e->getLine());
if (!empty($job_object->steps_data[$job_object->step_working]['uploadId'])) {
$s3->abortMultipartUpload(array('Bucket' => $job_object->job['s3bucket'], 'UploadId' => $job_object->steps_data[$job_object->step_working]['uploadId'], 'Key' => $job_object->job['s3dir'] . $job_object->backup_file));
//.........这里部分代码省略.........
示例2: upload
/**
* @param $file
* @param string $name
* @return mixed
*/
public function upload($file, $name = '')
{
if (empty($name)) {
$name = basename($file);
}
$content_type = BackWPup_Job::get_mime_type($file);
$xmlrequest = '<?xml version="1.0" encoding="UTF-8"?>';
$xmlrequest .= '<file>';
$xmlrequest .= '<displayName>' . mb_convert_encoding($name, 'UTF-8', $this->encoding) . '</displayName>';
$xmlrequest .= '<mediaType>' . $content_type . '</mediaType>';
$xmlrequest .= '</file>';
$this->doCall($this->folder, $xmlrequest, 'POST');
$getfiles = $this->getcontents('file');
foreach ($getfiles->file as $getfile) {
if ($getfile->displayName == $name) {
$this->doCall($getfile->ref . '/data', $file, 'PUT');
return $getfile->ref;
}
}
}
示例3: file_download
/**
* @param $jobid
* @param $get_file
*/
public function file_download($jobid, $get_file)
{
try {
set_include_path(get_include_path() . PATH_SEPARATOR . BackWPup::get_plugin_data('plugindir') . '/vendor/PEAR/');
$blobRestProxy = WindowsAzure\Common\ServicesBuilder::getInstance()->createBlobService('DefaultEndpointsProtocol=https;AccountName=' . BackWPup_Option::get($jobid, 'msazureaccname') . ';AccountKey=' . BackWPup_Encryption::decrypt(BackWPup_Option::get($jobid, 'msazurekey')));
$blob = $blobRestProxy->getBlob(BackWPup_Option::get($jobid, 'msazurecontainer'), $get_file);
if ($level = ob_get_level()) {
for ($i = 0; $i < $level; $i++) {
ob_end_clean();
}
}
@set_time_limit(300);
nocache_headers();
header('Content-Description: File Transfer');
header('Content-Type: ' . BackWPup_Job::get_mime_type($get_file));
header('Content-Disposition: attachment; filename="' . basename($get_file) . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . $blob->getProperties()->getContentLength());
fpassthru($blob->getContentStream());
die;
} catch (Exception $e) {
die($e->getMessage());
}
}
示例4: file_download
/**
* @param $jobid
* @param $get_file
*/
public function file_download($jobid, $get_file)
{
$backup_dir = esc_attr(BackWPup_Option::get((int) $jobid, 'backupdir'));
$backup_dir = BackWPup_File::get_absolute_path($backup_dir);
$get_file = realpath(trailingslashit($backup_dir) . basename($get_file));
if ($get_file && is_readable($get_file)) {
if ($level = ob_get_level()) {
for ($i = 0; $i < $level; $i++) {
ob_end_clean();
}
}
@set_time_limit(300);
nocache_headers();
header('Content-Description: File Transfer');
header('Content-Type: ' . BackWPup_Job::get_mime_type($get_file));
header('Content-Disposition: attachment; filename="' . basename($get_file) . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($get_file));
$handle = fopen($get_file, 'rb');
if ($handle) {
while (!feof($handle)) {
echo fread($handle, 10241024);
//chunks
flush();
}
fclose($handle);
}
die;
} else {
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
header("Status: 404 Not Found");
die;
}
}
示例5: load
/**
*
*/
public static function load()
{
//Create Table
self::$listtable = new BackWPup_Page_Logs();
switch (self::$listtable->current_action()) {
case 'delete':
if (!current_user_can('backwpup_logs_delete')) {
break;
}
if (is_array($_GET['logfiles'])) {
check_admin_referer('bulk-logs');
foreach ($_GET['logfiles'] as $logfile) {
$logfile = basename($logfile);
if (is_writeable(self::$listtable->log_folder . '/' . $logfile) && !is_dir(self::$listtable->log_folder . '/' . $logfile) && !is_link(self::$listtable->log_folder . '/' . $logfile)) {
unlink(self::$listtable->log_folder . '/' . $logfile);
}
}
}
break;
case 'download':
//Download Log
if (!current_user_can('backwpup_logs')) {
break;
}
check_admin_referer('download-log_' . trim($_GET['file']));
$log_file = trailingslashit(self::$listtable->log_folder) . basename(trim($_GET['file']));
$log_file = realpath($log_file);
if ($log_file && is_readable($log_file) && !is_dir($log_file) && !is_link($log_file)) {
if ($level = ob_get_level()) {
for ($i = 0; $i < $level; $i++) {
ob_end_clean();
}
}
@set_time_limit(300);
nocache_headers();
header('Content-Description: File Transfer');
header('Content-Type: ' . BackWPup_Job::get_mime_type($log_file));
header('Content-Disposition: attachment; filename="' . basename($log_file) . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($log_file));
@readfile($log_file);
die;
} else {
header('HTTP/1.0 404 Not Found');
die;
}
break;
}
//Save per page
if (isset($_POST['screen-options-apply']) && isset($_POST['wp_screen_options']['option']) && isset($_POST['wp_screen_options']['value']) && $_POST['wp_screen_options']['option'] == 'backwpuplogs_per_page') {
check_admin_referer('screen-options-nonce', 'screenoptionnonce');
global $current_user;
if ($_POST['wp_screen_options']['value'] > 0 && $_POST['wp_screen_options']['value'] < 1000) {
update_user_option($current_user->ID, 'backwpuplogs_per_page', (int) $_POST['wp_screen_options']['value']);
wp_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
exit;
}
}
add_screen_option('per_page', array('label' => __('Logs', 'backwpup'), 'default' => 20, 'option' => 'backwpuplogs_per_page'));
self::$listtable->prepare_items();
}
示例6: file_download
/**
* @param $jobid
* @param $get_file
*/
public function file_download($jobid, $get_file)
{
try {
$conn = new OpenCloud\Rackspace(self::get_auth_url_by_region(BackWPup_Option::get($jobid, 'rscregion')), array('username' => BackWPup_Option::get($jobid, 'rscusername'), 'apiKey' => BackWPup_Encryption::decrypt(BackWPup_Option::get($jobid, 'rscapikey'))));
$ostore = $conn->objectStoreService('cloudFiles', BackWPup_Option::get($jobid, 'rscregion'), 'publicURL');
$container = $ostore->getContainer(BackWPup_Option::get($jobid, 'rsccontainer'));
$backupfile = $container->getObject($get_file);
if ($level = ob_get_level()) {
for ($i = 0; $i < $level; $i++) {
ob_end_clean();
}
}
@set_time_limit(300);
nocache_headers();
header('Content-Description: File Transfer');
header('Content-Type: ' . BackWPup_Job::get_mime_type($get_file));
header('Content-Disposition: attachment; filename="' . basename($get_file) . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . $backupfile->getContentLength());
echo $backupfile->getContent();
die;
} catch (Exception $e) {
die($e->getMessage());
}
}
示例7: job_run_archive
/**
* @param $job_object
* @return bool
*/
public function job_run_archive(BackWPup_Job $job_object)
{
$job_object->substeps_todo = 1;
$job_object->log(sprintf(__('%d. Try to send backup with email …', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']), E_USER_NOTICE);
//check file Size
if (!empty($job_object->job['emailefilesize'])) {
if ($job_object->backup_filesize > $job_object->job['emailefilesize'] * 1024 * 1024) {
$job_object->log(__('Backup archive too big to be sent by email!', 'backwpup'), E_USER_ERROR);
$job_object->substeps_done = 1;
return TRUE;
}
}
$job_object->log(sprintf(__('Sending email to %s…', 'backwpup'), $job_object->job['emailaddress']), E_USER_NOTICE);
//get mail settings
$emailmethod = 'mail';
$emailsendmail = '';
$emailhost = '';
$emailhostport = '';
$emailsecure = '';
$emailuser = '';
$emailpass = '';
if (empty($job_object->job['emailmethod'])) {
//do so if i'm the wp_mail to get the settings
global $phpmailer;
// (Re)create it, if it's gone missing
if (!is_object($phpmailer) || !$phpmailer instanceof PHPMailer) {
require_once ABSPATH . WPINC . '/class-phpmailer.php';
require_once ABSPATH . WPINC . '/class-smtp.php';
$phpmailer = new PHPMailer(true);
}
//only if PHPMailer really used
if (is_object($phpmailer)) {
do_action_ref_array('phpmailer_init', array(&$phpmailer));
//get settings from PHPMailer
$emailmethod = $phpmailer->Mailer;
$emailsendmail = $phpmailer->Sendmail;
$emailhost = $phpmailer->Host;
$emailhostport = $phpmailer->Port;
$emailsecure = $phpmailer->SMTPSecure;
$emailuser = $phpmailer->Username;
$emailpass = $phpmailer->Password;
}
} else {
$emailmethod = $job_object->job['emailmethod'];
$emailsendmail = $job_object->job['emailsendmail'];
$emailhost = $job_object->job['emailhost'];
$emailhostport = $job_object->job['emailhostport'];
$emailsecure = $job_object->job['emailsecure'];
$emailuser = $job_object->job['emailuser'];
$emailpass = BackWPup_Encryption::decrypt($job_object->job['emailpass']);
}
//Generate mail with Swift Mailer
if (!class_exists('Swift', FALSE)) {
require BackWPup::get_plugin_data('plugindir') . '/vendor/SwiftMailer/swift_required.php';
}
if (function_exists('mb_internal_encoding') && (int) ini_get('mbstring.func_overload') & 2) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
}
try {
//Set Temp dir for mailing
Swift_Preferences::getInstance()->setTempDir(untrailingslashit(BackWPup::get_plugin_data('TEMP')))->setCacheType('disk');
// Create the Transport
if ($emailmethod == 'smtp') {
$transport = Swift_SmtpTransport::newInstance($emailhost, $emailhostport);
$transport->setUsername($emailuser);
$transport->setPassword($emailpass);
if ($emailsecure == 'ssl') {
$transport->setEncryption('ssl');
}
if ($emailsecure == 'tls') {
$transport->setEncryption('tls');
}
} elseif ($emailmethod == 'sendmail') {
$transport = Swift_SendmailTransport::newInstance($emailsendmail);
} else {
$job_object->need_free_memory($job_object->backup_filesize * 8);
$transport = Swift_MailTransport::newInstance();
}
// Create the Mailer using your created Transport
$emailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance(sprintf(__('BackWPup archive from %1$s: %2$s', 'backwpup'), date_i18n('d-M-Y H:i', $job_object->start_time, TRUE), esc_attr($job_object->job['name'])));
$message->setFrom(array($job_object->job['emailsndemail'] => $job_object->job['emailsndemailname']));
$message->setTo(array($job_object->job['emailaddress']));
$message->setBody(sprintf(__('Backup archive: %s', 'backwpup'), $job_object->backup_file), 'text/plain', strtolower(get_bloginfo('charset')));
$message->attach(Swift_Attachment::fromPath($job_object->backup_folder . $job_object->backup_file, $job_object->get_mime_type($job_object->backup_folder . $job_object->backup_file)));
// Send the message
$result = $emailer->send($message);
} catch (Exception $e) {
$job_object->log('Swift Mailer: ' . $e->getMessage(), E_USER_ERROR);
}
if (isset($mbEncoding)) {
mb_internal_encoding($mbEncoding);
}
if (!isset($result) || !$result) {
//.........这里部分代码省略.........