/**
	 * @see FileBackend::doStoreInternal()
	 */
	function doStoreInternal( array $params ) {
		$status = Status::newGood();
		list( $dstCont, $dstRel ) = $this->resolveStoragePath( $params['dst'] );
		try {
			$result = $this->storageClient->putBlob( $dstCont, $dstRel, $params['src']);
		}
		catch ( Exception $e ) {
			// TODO: Read exception. Are there different ones?
			$status->fatal( 'backend-fail-store', $dstRel, $dstCont );
		}
		return $status;
	}
예제 #2
0
 /**
  * Uploads file
  *
  * @param string $local_path
  * @param string $remote_path
  * @param bool $force_rewrite
  * @return array
  */
 function _upload($file, $force_rewrite = false)
 {
     $local_path = $file['local_path'];
     $remote_path = $file['remote_path'];
     if (!file_exists($local_path)) {
         return $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, 'Source file not found.');
     }
     $md5 = @md5_file($local_path);
     $content_md5 = $this->_get_content_md5($md5);
     if (!$force_rewrite) {
         try {
             $properties = $this->_client->getBlobProperties($this->_config['container'], $remote_path);
             $size = @filesize($local_path);
             if ($size === (int) $properties->Size && $content_md5 === $properties->ContentMd5) {
                 return $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_OK, 'File up-to-date.');
             }
         } catch (Exception $exception) {
         }
     }
     $headers = $this->_get_headers($file);
     $headers = array_merge($headers, array('Content-MD5' => $content_md5));
     try {
         $this->_client->putBlob($this->_config['container'], $remote_path, $local_path, array(), null, $headers);
     } catch (Exception $exception) {
         return $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf('Unable to put blob (%s).', $exception->getMessage()));
     }
     return $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_OK, 'OK');
 }
예제 #3
0
function dest_msazure()
{
    global $WORKING, $STATIC;
    $WORKING['STEPTODO'] = 2 + filesize($STATIC['JOB']['backupdir'] . $STATIC['backupfile']);
    trigger_error(sprintf(__('%d. try sending backup to a Microsoft Azure (Blob)...', 'backwpup'), $WORKING['DEST_MSAZURE']['STEP_TRY']), E_USER_NOTICE);
    require_once dirname(__FILE__) . '/../libs/Microsoft/WindowsAzure/Storage/Blob.php';
    need_free_memory(4194304 * 1.5);
    try {
        $storageClient = new Microsoft_WindowsAzure_Storage_Blob($STATIC['JOB']['msazureHost'], $STATIC['JOB']['msazureAccName'], $STATIC['JOB']['msazureKey']);
        if (!$storageClient->containerExists($STATIC['JOB']['msazureContainer'])) {
            trigger_error(sprintf(__('Microsoft Azure container "%s" not exists!', 'backwpup'), $STATIC['JOB']['msazureContainer']), E_USER_ERROR);
            return;
        } else {
            trigger_error(sprintf(__('Connected to Microsoft Azure container "%s"', 'backwpup'), $STATIC['JOB']['msazureContainer']), E_USER_NOTICE);
        }
        trigger_error(__('Upload to MS Azure now started... ', 'backwpup'), E_USER_NOTICE);
        $result = $storageClient->putBlob($STATIC['JOB']['msazureContainer'], $STATIC['JOB']['msazuredir'] . $STATIC['backupfile'], $STATIC['JOB']['backupdir'] . $STATIC['backupfile']);
        if ($result->Name == $STATIC['JOB']['msazuredir'] . $STATIC['backupfile']) {
            $WORKING['STEPTODO'] = 1 + filesize($STATIC['JOB']['backupdir'] . $STATIC['backupfile']);
            trigger_error(sprintf(__('Backup transferred to %s', 'backwpup'), 'https://' . $STATIC['JOB']['msazureAccName'] . '.' . $STATIC['JOB']['msazureHost'] . '/' . $STATIC['JOB']['msazuredir'] . $STATIC['backupfile']), E_USER_NOTICE);
            $STATIC['JOB']['lastbackupdownloadurl'] = $STATIC['WP']['ADMINURL'] . '?page=backwpupbackups&action=downloadmsazure&file=' . $STATIC['JOB']['msazuredir'] . $STATIC['backupfile'] . '&jobid=' . $STATIC['JOB']['jobid'];
            $WORKING['STEPSDONE'][] = 'DEST_MSAZURE';
            //set done
        } else {
            trigger_error(__('Can not transfer backup to Microsoft Azure!', 'backwpup'), E_USER_ERROR);
        }
        if ($STATIC['JOB']['msazuremaxbackups'] > 0) {
            //Delete old backups
            $backupfilelist = array();
            $blobs = $storageClient->listBlobs($STATIC['JOB']['msazureContainer'], $STATIC['JOB']['msazuredir']);
            if (is_array($blobs)) {
                foreach ($blobs as $blob) {
                    $file = basename($blob->Name);
                    if ($STATIC['JOB']['fileprefix'] == substr($file, 0, strlen($STATIC['JOB']['fileprefix'])) and $STATIC['JOB']['fileformart'] == substr($file, -strlen($STATIC['JOB']['fileformart']))) {
                        $backupfilelist[] = $file;
                    }
                }
            }
            if (sizeof($backupfilelist) > 0) {
                rsort($backupfilelist);
                $numdeltefiles = 0;
                for ($i = $STATIC['JOB']['msazuremaxbackups']; $i < sizeof($backupfilelist); $i++) {
                    $storageClient->deleteBlob($STATIC['JOB']['msazureContainer'], $STATIC['JOB']['msazuredir'] . $backupfilelist[$i]);
                    //delte files on Cloud
                    $numdeltefiles++;
                }
                if ($numdeltefiles > 0) {
                    trigger_error(sprintf(_n('One file deleted on Microsoft Azure container', '%d files deleted on Microsoft Azure container', $numdeltefiles, 'backwpup'), $numdeltefiles), E_USER_NOTICE);
                }
            }
        }
    } catch (Exception $e) {
        trigger_error(sprintf(__('Microsoft Azure API: %s', 'backwpup'), $e->getMessage()), E_USER_ERROR);
    }
    $WORKING['STEPDONE']++;
}
 /**
  * @see FileBackend::doStoreInternal()
  */
 function doStoreInternal(array $params)
 {
     $status = Status::newGood();
     list($dstCont, $dstRel) = $this->resolveStoragePath($params['dst']);
     if ($dstRel === null) {
         $status->fatal('backend-fail-invalidpath', $params['dst']);
         return $status;
     }
     if (empty($params['overwrite'])) {
         //Blob should not be overridden
         // Check if the destination object already exists
         if ($this->storageClient->blobExists($dstCont, $dstRel)) {
             $status->fatal('backend-fail-alreadyexists', $params['dst']);
             return $status;
         }
     }
     try {
         $result = $this->storageClient->putBlob($dstCont, $dstRel, $params['src']);
     } catch (Exception $e) {
         $status->fatal('backend-fail-store', $dstRel, $dstCont);
     }
     return $status;
 }
} else {
    // Connect to Windows Azure Storage in the cloud
    $table = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net', STORAGE_ACCOUNT, STORAGE_KEY);
    $blob = new Microsoft_WindowsAzure_Storage_Blob('blob.core.windows.net', STORAGE_ACCOUNT, STORAGE_KEY);
}
// Ensure the table exists
$table->createTableIfNotExists(TABLE_GUESTBOOK);
// Ensure the blob container exists
$blob->createcontainerIfNotExists(BLOB_GUESTBOOK);
// Set ACL
$blob->setContainerAcl(BLOB_GUESTBOOK, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC_CONTAINER);
// If the user submitted something put it into the table storage
// NOTE: Inputs are not cleaned for example purposes
if (isset($_POST['NameTextBox']) && isset($_POST['MessageTextBox'])) {
    $g = new GuestBookEntry();
    $image = $blob->putBlob(BLOB_GUESTBOOK, $_FILES['Image']['name'], $_FILES['Image']['tmp_name']);
    $g->GuestName = $_POST['NameTextBox'];
    $g->Message = $_POST['MessageTextBox'];
    $g->ImageUrl = $image->Url;
    $table->insertEntity(TABLE_GUESTBOOK, $g);
}
// User wishes to delete something
if (isset($_GET['Delete']) && isset($_GET['key'])) {
    $g = $table->retrieveEntityById(TABLE_GUESTBOOK, $_GET['Delete'], $_GET['key']);
    $table->deleteEntity(TABLE_GUESTBOOK, $g);
    header("Location: index.php");
}
// Get all the guest book entries for display
$entries = $table->retrieveEntities(TABLE_GUESTBOOK);
?>
예제 #6
0
<?php

require_once 'Microsoft/WindowsAzure/Storage/Blob.php';
$storageClient = new Microsoft_WindowsAzure_Storage_Blob();
// upload del file picture.jpg in Windows Azure
$result = $storageClient->putBlob('testcontainer', 'picture.jpg', '/path/to/picture.jpg');
echo 'File inserito: ' . $result->Name;