Example #1
0
 public function touch($path, $mtime = null)
 {
     $path = $this->normalizePath($path);
     if (is_null($mtime)) {
         $mtime = time();
     }
     $metadata = array('timestamp' => $mtime);
     if ($this->file_exists($path)) {
         if ($this->is_dir($path) && $path != '.') {
             $path .= '/';
         }
         $object = $this->fetchObject($path);
         if ($object->saveMetadata($metadata)) {
             // invalidate target object to force repopulation on fetch
             $this->objectCache->remove($path);
         }
         return true;
     } else {
         $mimeType = \OC::$server->getMimeTypeDetector()->detectPath($path);
         $customHeaders = array('content-type' => $mimeType);
         $metadataHeaders = DataObject::stockHeaders($metadata);
         $allHeaders = $customHeaders + $metadataHeaders;
         $this->getContainer()->uploadObject($path, '', $allHeaders);
         // invalidate target object to force repopulation on fetch
         $this->objectCache->remove($path);
         return true;
     }
 }
Example #2
0
 public function touch($path, $mtime = null)
 {
     $path = $this->normalizePath($path);
     if (is_null($mtime)) {
         $mtime = time();
     }
     $metadata = array('timestamp' => $mtime);
     if ($this->file_exists($path)) {
         if ($this->is_dir($path) && $path != '.') {
             $path .= '/';
         }
         $object = $this->container->getPartialObject($path);
         $object->saveMetadata($metadata);
         return true;
     } else {
         $customHeaders = array('content-type' => 'text/plain');
         $metadataHeaders = DataObject::stockHeaders($metadata);
         $allHeaders = $customHeaders + $metadataHeaders;
         $this->container->uploadObject($path, '', $allHeaders);
         return true;
     }
 }
Example #3
0
 public function touch($path, $mtime = null)
 {
     $path = $this->normalizePath($path);
     if (is_null($mtime)) {
         $mtime = time();
     }
     $metadata = array('timestamp' => $mtime);
     if ($this->file_exists($path)) {
         $object = $this->getContainer()->getPartialObject($path);
         $object->saveMetadata($metadata);
         return true;
     } else {
         $mimeType = \OC_Helper::getMimetypeDetector()->detectPath($path);
         $customHeaders = array('content-type' => $mimeType);
         $metadataHeaders = DataObject::stockHeaders($metadata);
         $allHeaders = $customHeaders + $metadataHeaders;
         $this->getContainer()->uploadObject($path, '', $allHeaders);
         return true;
     }
 }
 * limitations under the License.
 */
//
// Pre-requisites:
// * Prior to running this script, you must setup the following environment variables:
//   * RAX_USERNAME: Your Rackspace Cloud Account Username, and
//   * RAX_API_KEY:  Your Rackspace Cloud Account API Key
// * There exists a container named 'logos' in your Object Store. Run
//   create-container.php if you need to create one first.
//
require __DIR__ . '/../../vendor/autoload.php';
use OpenCloud\Rackspace;
use OpenCloud\ObjectStore\Resource\DataObject;
// 1. Instantiate a Rackspace client.
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array('username' => getenv('RAX_USERNAME'), 'apiKey' => getenv('RAX_API_KEY')));
// 2. Obtain an Object Store service object from the client.
$region = 'DFW';
$objectStoreService = $client->objectStoreService(null, $region);
// 3. Get container.
$container = $objectStoreService->getContainer('logos');
// 4. Upload an object to the container.
$localFileName = __DIR__ . '/php-elephant.jpg';
$remoteFileName = 'php-elephant.jpg';
$metadata = array('author' => 'Jane Doe');
$customHeaders = array();
$metadataHeaders = DataObject::stockHeaders($metadata);
$allHeaders = $customHeaders + $metadataHeaders;
$fileData = fopen($localFileName, 'r');
$container->uploadObject($remoteFileName, $fileData, $allHeaders);
// Note that while we call fopen to open the file resource, we do not call fclose at the end.
// The file resource is automatically closed inside the uploadObject call.
 public function upload_object($file_name, $file_location, array $meta_data = array())
 {
     $data = fopen($file_location . $file_name, 'r+');
     $metaHeaders = DataObject::stockHeaders($meta_data);
     $this->container->uploadObject($this->virtual_folder . $file_name, $data, $metaHeaders);
     log_message('debug', 'Rackspace Cloudfiles: File ' . $this->virtual_folder . $file_name . ' was uploaded');
 }
Example #6
0
function upload_data($authuserid)
{
    $username = "******";
    // username
    $key = "0d5739ba0696428f885890282d3ba150";
    // api key
    //Rackspace client
    $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array('username' => $username, 'apiKey' => $key));
    //Authenticate client
    $client->authenticate();
    $service = $client->objectStoreService('cloudFiles');
    $container = $service->getContainer('userimages');
    //Figure out the user first name and last name based on the $name variable
    //We must have got some dimensions to crop the images, lets get that set
    $profile_image_crop_x = $_POST['x'];
    $profile_image_crop_y = $_POST['y'];
    $profile_image_crop_w = $_POST['w'];
    $profile_image_crop_h = $_POST['h'];
    if ($_FILES['profile_image']['tmp_name'] != "") {
        $imageProcessor = new ImageManipulator($_FILES['profile_image']['tmp_name']);
        if ($profile_image_crop_w > 1 && $profile_image_crop_h > 1) {
            $croppedImage = $imageProcessor . crop($profile_image_crop_x, $profile_image_crop_y, $profile_image_crop_x + $profile_image_crop_w, $profile_image_crop_y + $profile_image_crop_h);
        }
        $imageProcessor->save($basePath . $target_profile_pic_name);
        //Read back the file so that we can now upload it to Rackspace CDN.
        //Common Meta
        $meta = array('Author' => $name, 'Origin' => 'FINAO Web');
        $metaHeaders = DataObject::stockHeaders($meta);
        $data = fopen($basePath . $target_profile_pic_name, 'r+');
        $container->uploadObject($target_profile_pic_name, $data, $metaHeaders);
        $targ_w = 150;
        $targ_h = 150;
        $jpeg_quality = 90;
        $profile_thumb_image = $imageProcessor->resample($targ_w, $targ_h);
        $imageProcessor->save($basePath . $target_profile_pic_thumb);
        $data = fopen($basePath . $target_profile_pic_thumb, 'r+');
        $container->uploadObject($target_profile_pic_thumb, $data, $metaHeaders);
    }
    if ($_FILES['profile_bg_image']['tmp_name'] != "") {
        @move_uploaded_file($_FILES['profile_bg_image']['tmp_name'], 'images/uploads/profileimages/' . $target_banner_pic_name);
        //Common Meta
        $meta = array('Author' => $name, 'Origin' => 'FINAO Web');
        $metaHeaders = DataObject::stockHeaders($meta);
        $data = fopen($basePath . $target_banner_pic_name, 'r+');
        $container->uploadObject($target_banner_pic_name, $data, $metaHeaders);
    }
}