我遇到了同样的问题,我通过在将文件提交到S3时设置http标头“ content-disposition”来解决它,该SDK版本是适用于PHP 3.x的AWS开发工具包。这是文档http://docs.amazonaws.cn/zh_CN/aws-sdk-php/latest/api-s3-2006-03-01.html#putobject
我的一段代码
public function __construct($config)
{
$this->handle = new S3Client([
'credentials' => array(
'key' => $config['key'],
'secret' => $config['secret'],
),
...
]);
...
}
public function putObject($bucket, $object_name, $source_file, $content_type = false, $acl = 'public-read', $filename = '')
{
try {
$params = [
'Bucket' => $bucket,
'Key' => $object_name,
'SourceFile' => $source_file,
'ACL' => $acl,
];
if ($content_type) $params['ContentType'] = $content_type;
if ($filename) $params['ContentDisposition'] = 'attachment; filename="' . $filename . '"';
$result = $this->handle->putObject($params);
...
}
catch(Exception $e)
{
...
}
}