我是CodeIgniter的新手,我正在做一個將CI應用程序與Amazon S3集成的poc。我使用了github的S3 PHP類(https://github.com/psugand/CodeIgniter-S3),並能夠列出存儲桶和列表對象以查看文件。 我的問題是首先我不能從視圖窗體中將值發佈到控制器,然後需要檢查如何將文件上傳到s3。也很好用在putObject函數中使用URI是什麼?在CodeIgniter中表單發佈並上傳到AWS S3不起作用
以下是控制器&查看文件。請讓我知道我們如何形成發佈到控制器,然後上傳到S3。
我的控制器的文件 - S3demo.php
class S3demo extends CI_Controller {
public function index()
{
//Var Declaration
$data['bucketName'] = "demacrtest";
// Load Library
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('s3');
// Get all required Data
$data['bucket_list'] = $this->s3->listBuckets();
$header_data['title'] = "CI and S3 Demo";
$data['object_list'] = $this->s3->getBucket($data['bucketName']);
// Load Views
$this->load->view('common/header', $header_data);
$this->load->view('s3_demo', $data);
$this->load->view('common/footer');
}
public function doUploadtoS3(){
echo "in";
//Var Declaration
$data['bucketName'] = "demacrtest";
$uri = "dms/";
// Load Library
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('s3');
// GET DATA POST FROM FORM
$data = array(
'files' => $this->input->post('uploadedfiles')
);
// DISPLAY DATA
echo "<pre>";
print_r($data);
// PUT with custom headers:
$put = S3::putObject(
S3::inputFile($data),
$data['bucketName'],
$uri,
S3::ACL_PUBLIC_READ,
array(),
array(// Custom $requestHeaders
"Cache-Control" => "max-age=315360000",
"Expires" => gmdate("D, d M Y H:i:s T", strtotime("+5 years"))
)
);
}
}
我查看文件 - s3_demo.php
<div class="container-fluid">
<div class="row">
<div class="col-sm-6">
<h1>List of S3 buckets</h1>
<div>
<ul>
<?php foreach ($bucket_list as $bucket){?>
<li><?php echo $bucket;?></li>
<?php }?>
</ul>
</div>
</div>
<div class="col-sm-6">
<h1>List of objects in bucket - <?php echo $bucketName; ?></h1>
<div>
<ul>
<?php foreach ($object_list as $objects){?>
<li><?php echo $objects['name']; ?></li>
<?php }?>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="upload-form">
<h3>Upload to S3 Form</h3>
<form class="form-horizontal" role="form" action="s3demo/doUploadtoS3" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="name" class ="control-label col-sm-3">Upload</label>
<div class="col-sm-8">
<input id="input-2" name="uploadedfiles[]" type="file" class="file">
</div>
</div>
<div class="col-sm-offset-2 col-sm-8">
<button type="submit" class="btn btn-default">Upload</button>
</div>
</form>
</div>
</div>
還試圖用CI表單功能,但它是沒有用的 '<?PHP的回聲form_open( 's3demo/doUploadtoS3')?>' 即使這是不工作... –