[英]Codeigniter Domain Masking for Amazon S3 Bucket
在我的Web应用程序中,我正在使用Amazon S3存储桶保存图像,并且我需要我的codeigniter主机来显示S3存储桶中的图像,但要显示主机URL。
例如:
mywebapp.com/products/image1.jpg
将显示mywebapp.s3.amazonaws.com/products/image1.jpg
内容
我正在使用Codeigniter,但不确定在我的Codeigniter项目中还是从其他配置中解决此问题。
如果尚未完成,请首先在构造函数中加载url helper:
$this->load->helper('url');
然后,每当您需要重定向时,您都可以简单地调用:
$s3_url = "https://mywebapp.s3.amazonaws.com/products/image1.jpg";
// you can omit the last two parameters for the default redirect
redirect($s3_url, 'location', 301);
我想您想要访问URL并获取图像的服务,这是我的解决方案
<?php if (!defined('BASEPATH')) die();
class Img extends CI_Controller {
public function __construct ()
{
parent::__construct();
$this->load->helper('url');
// this is the db model where you store the image's urls
$this->load->model('images_model', 'img_m');
}
// accessed as example.com/img/<image_id>
// redirects to the appropiate s3 URL
public function index()
{
// get the second segment (returns false if not set)
$image_id = $this->uri->segment(2);
// if there was no image in the url set:
if ($image_id === false)
{
// load an image index view
$this->load->view('image_index_v');
exit;
}
$url = $this->img_m->get_url($image_id);
// get_url() should return something like this:
$url = "https://mywebapp.s3.amazonaws.com/products/image1.jpg";
// then you simply call:
redirect($url, 'location', 301);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.