/** * Move a local file to S3 storage. * * @param string $source Local filesystem path to file. * @param string $dest Destination path. */ public function store($source, $dest) { $objectName = $this->_getObjectName($dest); // If an expiration time is set, we're uploading private files // and using signed URLs. If not, we're uploading public files. if ($this->_getExpiration()) { $meta[Zend_Service_Amazon_S3::S3_ACL_HEADER] = Zend_Service_Amazon_S3::S3_ACL_PRIVATE; } else { $meta[Zend_Service_Amazon_S3::S3_ACL_HEADER] = Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ; } $status = $this->_s3->putFileStream($source, $objectName, $meta); if (!$status) { throw new Omeka_Storage_Exception('Unable to store file.'); } _log("Omeka_Storage_Adapter_ZendS3: Stored '{$source}' as '{$objectName}'."); unlink($source); }
protected function _fileTest($filename, $object, $type, $exp_type, $stream = false) { if ($stream) { $this->_amazon->putFile($filename, $object, array(S3\S3::S3_CONTENT_TYPE_HEADER => $type)); } else { $this->_amazon->putFileStream($filename, $object, array(S3\S3::S3_CONTENT_TYPE_HEADER => $type)); } $data = file_get_contents($filename); $this->assertTrue($this->_amazon->isObjectAvailable($object)); $info = $this->_amazon->getInfo($object); $this->assertEquals('"' . md5_file($filename) . '"', $info["etag"]); $this->assertEquals(filesize($filename), $info["size"]); $this->assertEquals($exp_type, $info["type"]); $fdata = $this->_amazon->getObject($object); $this->assertEquals($data, $fdata); }
function s3_put_file($access_key_id, $secret_access_key, $bucket_path, $file_path, $mime) { $result = FALSE; if ($access_key_id && $secret_access_key && $bucket_path && $file_path) { try { $s3 = new Zend_Service_Amazon_S3($access_key_id, $secret_access_key); $meta = array(); $meta[Zend_Service_Amazon_S3::S3_ACL_HEADER] = Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ; if ($mime) { $meta[Zend_Service_Amazon_S3::S3_CONTENT_TYPE_HEADER] = $mime; } if ($s3->putFileStream($file_path, $bucket_path, $meta)) { $result = TRUE; } } catch (Exception $ex) { //print $ex->getMessage(); } } return $result; }