【发布时间】:2014-09-07 20:03:51
【问题描述】:
我有一个 CodeIgniter 应用程序,视图中有一个表单。该表单接受随后将上传到 Amazon S3 的文件。我正在使用这个库与 S3 对话:https://github.com/psugand/CodeIgniter-S3。当我上传小文件时,该脚本工作正常。我最初收到一个错误,说不允许您请求的操作。我根据此Action you have requested is not allowed error 将问题追溯到CSRF 保护并将CSRF 保护设置为false。现在,您请求的操作是不允许的。 已消失,但大文件仍未上传。该文件被上传,然后页面只是闪烁并且表单本身清空。不知道为什么。
我的应用程序在 Amazon ElasticBeanstalk 64 位 PHP 机器上运行。即使在本地主机上我也会遇到同样的错误。这是我的代码:
查看
<?php echo form_open_multipart('landing/submit'); ?>
<div class="form-group">
<label for="exampleInputName">Name</label>
<input type="text" class="form-control" id="app_name" placeholder="Name" name="name" required>
</div>
<div class="form-group">
<label for="exampleInputEmail1">E-mail</label>
<input type="text" class="form-control" id="app_email" placeholder="E-mail" name="email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">PM XML File</label>
<input type="file" class="form-control" id="app_file" name="file" placeholder="File">
</div>
<button type="submit" class="btn btn-block btn-orange btn-Submit" name="submit">SUBMIT</button>
<small id="mail_msg"></small>
<?php form_close(); ?>
控制器
public function submit()
{
if (isset($_POST['submit']))
{
$name = $this->input->post('name');
$email = $this->input->post('email');
$fileName = $_FILES['file']['name'];
$fileTempName = $_FILES['file']['tmp_name'];
$this->load->library('s3');
$input = $this->s3->inputFile($fileTempName);
$result = $this->s3->putObject(
$input,
'pmxmls',
$name . '_' . $email . '_' . $fileName,
S3::ACL_PUBLIC_READ,
array(),
array("Cache-Control" => "max-age=315360000", "Expires" => gmdate("D, d M Y H:i:s T", strtotime("+5 years"))
));
is_integer($result);
if ($result == '1')
{
@session_start();
$_SESSION['submit'] = true;
redirect(base_url());
}
else
{
echo 'There was an error.';
}
}
else
{
redirect(base_url());
}
}
【问题讨论】:
-
“上传的大文件”多大?
-
超过 50 MB。大约 75 MB。我还希望用户上传数百 MB 大小的文件。
-
检查 php.ini 的 max_input_time、max_execution_time、post_max_size 和 upload_max_filesize
标签: php codeigniter amazon-s3