5 function amazons3_pagesetup() {
8 function amazons3_init() {
12 Fill in your bucket name to use S3!
14 Also remember to fill in your key and secret key in s3.class.php.
17 if (empty($CFG->files
->amazons3
->bucket
)) {
18 $CFG->files
->amazons3
->bucket
= "";
23 $CFG->files
->default_handler
= "amazons3";
24 $CFG->files
->handler
["amazons3"] = "amazons3_passthru";
26 if (empty($CFG->files
->siteid
)) {
27 $CFG->files
->siteid
= $CFG->dbuser
;
29 listen_for_event("file","create","amazons3_create");
30 listen_for_event("file","delete","amazons3_delete");
33 function amazons3_upload($originalname, $filePath, $bucket = NULL) {
35 if ($bucket == NULL) {
36 $bucket = $CFG->files
->amazons3
->bucket
;
38 require_once("s3.class.php");
39 $s3transfer = new s3();
40 $result = $s3transfer->getObjects($bucket);
41 if (substr_count($result,"The specified bucket does not exist")) {
42 $s3transfer->putBucket($bucket);
44 if ($data = file_get_contents($filePath)) {
45 $output = $s3transfer->putObject($originalname, $data, $bucket);
46 header("content-type: ".$s3transfer->getResponseContentType());
50 function amazons3_passthru($filename, $bucket = NULL) {
53 $filename = $CFG->files
->siteid
. "/" . str_replace($CFG->dataroot
, "", $filename);
55 if ($bucket == NULL) {
56 $bucket = $CFG->files
->amazons3
->bucket
;
59 require_once($CFG->dirroot
. 'lib/filelib.php');
60 $mimetype = mimeinfo('type',$filename);
61 require_once("s3.class.php");
62 $s3transfer = new s3();
63 $metadata = $s3transfer->getObjectInfo($filename, $bucket, NULL, $mimetype);
64 $mimetype = mimeinfo('type',$filename);
65 // header("Content-type: ".$mimetype);
66 return $s3transfer->getObject($filename,$bucket);
69 function amazons3_create($object_type, $event, $object) {
71 amazons3_upload($CFG->files
->siteid
. "/" . $object->location
, $CFG->dataroot
. $object->location
);
72 @unlink
($CFG->dataroot
. $object->location
);
73 $object->handler
= "amazons3";
77 function amazons3_delete($object_type, $event, $object) {
79 require_once("s3.class.php");
80 $s3transfer = new s3();
81 $s3transfer->deleteObject($CFG->files
->siteid
. "/" . $object->location
, $CFG->files
->amazons3
->bucket
);