Skip to content

Instantly share code, notes, and snippets.

@zirosas
Created June 26, 2013 20:16
Show Gist options
  • Save zirosas/5871216 to your computer and use it in GitHub Desktop.
Save zirosas/5871216 to your computer and use it in GitHub Desktop.
PHP s3 uploading, require (S3.php)
function s3_uploading ($flname, $vid, $cover) {
if($_FILES[$flname]["name"]) {
$photodir;
try {
if ((($_FILES[$flname]["type"] == "image/gif") || ($_FILES[$flname]["type"] == "image/jpg") || ($_FILES[$flname]["type"] == "image/jpeg") || ($_FILES[$flname]["type"] == "image/pjpeg")) && ($_FILES[$flname]["size"] < 1000000)) {
if ($_FILES[$flname]["error"] > 0) {
echo "Return Code: " . $_FILES[$flname]["error"] . "<br />";
}
else {
//include the S3 class
if (!class_exists('S3'))require_once('S3.php');
//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', '');
if (!defined('awsSecretKey')) define('awsSecretKey', '');
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
//retreive post variables
$fileName = $_FILES[$flname]["name"];
$fileTempName = $_FILES[$flname]['tmp_name'];
$imgName = "/".$fileName;
$thumb = "/thumbs/".$fileName;
//move the file
if ($s3->putObjectFile($fileTempName, "bucketname", $imgName, S3::ACL_PUBLIC_READ)) {
createThumbs($_FILES[$flname]['tmp_name'], $photodir."thumbs/". $_FILES[$flname]["name"], 100);
$s3->putObjectFile($photodir."thumbs/". $_FILES[$flname]["name"], "bucketname", $thumb, S3::ACL_PUBLIC_READ);
echo "<strong>We successfully uploaded your file.</strong>";
}
else {
echo "<strong>Something went wrong while uploading your file... sorry.</strong>";
}
}
}
else {
echo "Invalid file".$_FILES[$flname]["error"];
}
}
catch (Exception $e) {
echo $e;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment