本文整理汇总了PHP中S3::SaveContents方法的典型用法代码示例。如果您正苦于以下问题:PHP S3::SaveContents方法的具体用法?PHP S3::SaveContents怎么用?PHP S3::SaveContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类S3
的用法示例。
在下文中一共展示了S3::SaveContents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* @method POST
*/
function get()
{
// get token
$token = Utilities::ValidateJWTToken(apache_request_headers());
// check if token is not null
if ($token != NULL) {
// get a reference to the site, user
$site = Site::GetBySiteId($token->SiteId);
parse_str($this->request->data, $request);
// parse request
$overwrite = NULL;
$folder = 'files';
if (isset($_REQUEST['overwrite'])) {
$overwrite = $_REQUEST['overwrite'];
}
if (isset($_REQUEST['folder'])) {
$folder = $_REQUEST['folder'];
}
$arr = array();
// Get uploaded file info
$filename = $_FILES['file']['name'];
$file = $_FILES['file']['tmp_name'];
$contentType = $_FILES['file']['type'];
$size = intval($_FILES['file']['size'] / 1024);
// overwrite if applicable
if ($overwrite != NULL) {
$filename = $overwrite;
}
$parts = explode(".", $filename);
$ext = end($parts);
// get extension
$ext = strtolower($ext);
// convert to lowercase
$thumbnail = 't-' . $filename;
// allowed filetypes
$allowed = explode(',', ALLOWED_FILETYPES);
// trim and lowercase all items in the aray
$allowed = array_map('trim', $allowed);
$allowed = array_map('strtolower', $allowed);
// save image
if ($ext == 'png' || $ext == 'jpg' || $ext == 'gif' || $ext == 'svg') {
// upload image
$arr = Image::SaveImageWithThumb($site, $filename, $file, $folder);
// set local URL
$url = $site['Domain'];
// set URL if on S3
if (FILES_ON_S3 == true) {
$url = str_replace('{{bucket}}', $site['Bucket'], S3_URL);
$url = str_replace('{{site}}', $site['FriendlyId'], $url);
}
// create array
$arr = array('filename' => $filename, 'fullUrl' => $url . '/' . $folder . '/' . $filename, 'thumbUrl' => $site['Domain'] . '/' . $folder . '/thumbs/' . $filename, 'extension' => $ext, 'isImage' => true, 'width' => $arr['width'], 'height' => $arr['height']);
} else {
if (in_array($ext, $allowed)) {
// save file if it is allowed
// save file to directory
$directory = SITES_LOCATION . '/' . $site['FriendlyId'] . '/' . $folder . '/';
// set url
$url = $site['Domain'];
// set URL if on S3
if (FILES_ON_S3 == true) {
// meta is blank for non-images
$meta = array();
$type = $contentType;
echo 'test';
echo $filename;
// save file with meta-data
S3::SaveContents($site, $type, $filename, $file, $meta, $folder);
$url = str_replace('{{bucket}}', $site['Bucket'], S3_URL);
$url = str_replace('{{site}}', $site['FriendlyId'], $url);
} else {
// upload file
Utilities::SaveFile($directory, $filename, $file);
}
$arr = array('filename' => $filename, 'fullUrl' => $url . '/' . $folder . '/' . $filename, 'thumbUrl' => NULL, 'extension' => $ext, 'isImage' => false, 'width' => -1, 'height' => -1);
} else {
return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
}
}
// return a json response
$response = new Tonic\Response(Tonic\Response::OK);
$response->contentType = 'application/json';
$response->body = json_encode($arr);
return $response;
} else {
// return an unauthorized exception (401)
return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
}
}
示例2: CreateThumb
public static function CreateThumb($site, $image, $filename, $folder = 'files')
{
// directory
$dir = SITES_LOCATION . '/' . $site['FriendlyId'] . '/' . $folder . '/';
// set thumb size
$target_w = THUMB_MAX_WIDTH;
$target_h = THUMB_MAX_HEIGHT;
list($curr_w, $curr_h, $type, $attr) = Image::getImageInfo($image);
$ext = 'jpg';
switch ($type) {
// create image
case IMAGETYPE_JPEG:
$ext = 'jpg';
break;
case IMAGETYPE_PNG:
$ext = 'png';
break;
case IMAGETYPE_GIF:
$ext = 'gif';
break;
case 'image/svg+xml':
$ext = 'svg';
break;
default:
return false;
}
$scale_h = $target_h / $curr_h;
$scale_w = $target_w / $curr_w;
$factor_x = $curr_w / $target_w;
$factor_y = $curr_h / $target_h;
if ($factor_x > $factor_y) {
$factor = $factor_y;
} else {
$factor = $factor_x;
}
$up_w = ceil($target_w * $factor);
$up_h = ceil($target_h * $factor);
$x_start = ceil(($curr_w - $up_w) / 2);
$y_start = ceil(($curr_h - $up_h) / 2);
switch ($type) {
// create image
case IMAGETYPE_JPEG:
$n_img = imagecreatefromjpeg($image);
break;
case IMAGETYPE_PNG:
$n_img = imagecreatefrompng($image);
break;
case IMAGETYPE_GIF:
$n_img = imagecreatefromgif($image);
break;
case 'image/svg+xml':
break;
default:
return false;
}
$dst_img = ImageCreateTrueColor($target_w, $target_h);
switch ($type) {
// fix for transparency issues
case IMAGETYPE_PNG:
imagealphablending($dst_img, true);
imagesavealpha($dst_img, true);
$transparent_color = imagecolorallocatealpha($dst_img, 0, 0, 0, 127);
imagefill($dst_img, 0, 0, $transparent_color);
break;
case IMAGETYPE_GIF:
$transparency_index = imagecolortransparent($dst_img);
if ($transparency_index >= 0) {
$transparent_color = imagecolorsforindex($dst_img, $transparency_index);
$transparency_index = imagecolorallocate($dst_img, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
imagefill($dst_img, 0, 0, $transparency_index);
imagecolortransparent($dst_img, $transparency_index);
}
break;
default:
break;
}
// (for testing) die('curr_w='.$curr_w.' curr_h='.$curr_h.' x_start='.$x_start.' y_start='.$y_start.' target_w='.$target_w.' target_h='.$target_h.' up_w='.$up_w.' up_h='.$up_h);
if ($type != 'image/svg+xml') {
imagecopyresampled($dst_img, $n_img, 0, 0, $x_start, $y_start, $target_w, $target_h, $up_w, $up_h);
}
//return $dst_img;
$full = $dir . 'thumbs/' . $filename;
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
switch ($ext) {
case 'jpg':
// save file on S3
if (FILES_ON_S3 == true) {
// write image and copy buffer
ob_start();
imagejpeg($dst_img, NULL, 100);
$contents = ob_get_contents();
ob_end_clean();
$meta = array('width' => $target_w, 'height' => $target_h);
S3::SaveContents($site, $type, 'thumbs/' . $filename, $contents, $meta, $folder);
} else {
// save file locally
imagejpeg($dst_img, $full, 100);
}
//.........这里部分代码省略.........