public function save($local_file, $remote_file) { $url = $this->absolutize($remote_file); // Cache the fileinfo binarypool_fileinfo::setCache($url, binarypool_fileinfo::getFileinfo($local_file)); $this->removeCache($remote_file); $this->flushCache($remote_file); $retval = $this->client->putObjectFile($local_file, $this->cfg['bucket'], $remote_file, S3::ACL_PUBLIC_READ, array(), binarypool_mime::getMimeType($local_file)); if ($retval === false) { throw new binarypool_exception(105, 500, "Could not copy file to its final destination on S3: {$remote_file}"); } return $retval; }
/** * Load asset file into memory. * * @param $file: Filename to load data from. */ private function load($file) { // Load document into RAM, do checks $dom = new DOMDocument(); if (!$dom->loadXML($this->storage->getFile($file))) { throw new binarypool_exception(113, 500, "Invalid asset file: {$file}"); } $xp = new DOMXPath($dom); if ($this->getXPathValue($xp, '/registry/@version') != '3.0') { throw new binarypool_exception(113, 500, "Invalid asset file: {$file}"); } // Get asset properties $this->created = intval($this->getXPathValue($xp, '/registry/created')); $this->expiry = intval($this->getXPathValue($xp, '/registry/expiry')); // Get callbacks $this->callbacks = array(); $res = $xp->query('/registry/callback'); foreach ($res as $item) { $this->addCallback($item->nodeValue); } // Get base path $assetDirectory = dirname($file); $this->basepath = $this->getXPathValue($xp, '/registry/basepath'); if (!$this->basepath) { $path = $this->getXPathValue($xp, '/registry/items/item/location'); $this->basepath = substr($path, 0, strrpos($path, '/') + 1); } // Load renditions & original $this->renditions = array(); $nodes = $xp->query('/registry/items/item'); foreach ($nodes as $node) { $isOriginal = $node->getAttribute('isRendition') == 'false'; $renditionName = $xp->query('rendition', $node)->item(0)->nodeValue; $renditionLocationNode = $xp->query('location', $node)->item(0); $this->locationAbsolute = $renditionLocationNode->getAttribute('absolute') == 'true'; $renditionLocation = $renditionLocationNode->nodeValue; if (!$this->locationAbsolute) { $renditionLocation = substr($renditionLocation, strrpos($renditionLocation, '/')); $renditionLocation = $assetDirectory . $renditionLocation; $renditionLocationAbs = $this->storage->absolutize($renditionLocation); } else { $renditionLocationAbs = $renditionLocation; } $hashNodes = $xp->query('hash', $node); $hash = ''; if ($hashNodes->length == 0) { $fileinfo = binarypool_fileinfo::getFileinfo($renditionLocationAbs); $hash = $fileinfo['hash']; } else { $hash = $hashNodes->item(0)->nodeValue; } $fileinfo = array('mime' => $xp->query('mimetype', $node)->item(0)->nodeValue, 'size' => intval($xp->query('size', $node)->item(0)->nodeValue), 'hash' => $hash); binarypool_fileinfo::setCache($renditionLocationAbs, $fileinfo); if ($isOriginal) { $this->setOriginal($renditionLocationAbs); $this->type = $node->getAttribute('type'); } else { $this->setRendition($renditionName, $renditionLocationAbs); } } }