Skip to content

Instantly share code, notes, and snippets.

@DrewDahlman
Last active January 14, 2018 20:42
Show Gist options
  • Save DrewDahlman/e40005afde41e11bdd9581faf5b9bbec to your computer and use it in GitHub Desktop.
Save DrewDahlman/e40005afde41e11bdd9581faf5b9bbec to your computer and use it in GitHub Desktop.
<?php
include_once(dirname(__FILE__) . "/s3.php");
class Uploader {
var $settings;
var $file;
public function __construct( $file_name, $tmp_file, $dest ){
$this->settings["bucket"] = get_site_option("tantan_wordpress_s3")["bucket"];
$this->settings["awsAccessKey"] = get_site_option(Amazon_Web_Services::SETTINGS_KEY)["access_key_id"];
$this->settings["awsSecretKey"] = get_site_option(Amazon_Web_Services::SETTINGS_KEY)["secret_access_key"];
$this->settings["tmp_file"] = $tmp_file;
$this->settings["file_name"] = $dest . $file_name;
$this->settings["file_url"] = "http://". $this->settings["bucket"] . ".s3.amazonaws.com/" . $this->settings["file_name"];
}
function upload(){
$s3 = new S3(
$this->settings["awsAccessKey"],
$this->settings["awsSecretKey"]
);
$s3->putBucket(
$this->settings["bucket"],
S3::ACL_PUBLIC_READ,
0
);
return $s3->putObjectFile($this->settings["tmp_file"], $this->settings["bucket"], $this->settings["file_name"], S3::ACL_PUBLIC_READ, array(), "application/json");
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment