[英]How can I download and execute a php file in a bucket using Amazon S3 SDK?
如何使用S3 SDK在Amazon中连接存储桶时执行PHP文件?
我尝试使用$s3->getBucket
,我得到了以下数组。 但我需要执行此文件的结果。
Array
(
[content/content.php] => Array
(
[name] => content/content.php
[time] => 1353105202
[size] => 1223
[hash] => 355c51389b51814d4b6c822a6ec28cfe
)
)
是否有任何函数/方法来执行PHP文件?
您无法直接在Amazon S3上执行PHP文件。
你需要做的是下载它的内容,将内容写入文件,然后运行文件本身(通过使用include()或require())。
如果文件直接输出内容,您可以将其包装在ob_start()和ob_get_clean()中以获取任何输出。
$source = $s3->getObject($bucket, $object);
$filename = tempnam('/tmp');
$file = fopen($filename, 'w');
fwrite($file, $source);
fclose($file);
ob_start();
require_once $filename;
$result = ob_get_clean();
echo $result; // the result of the executed PHP.
您可以使用s3fs之类的东西在本地文件系统中安装S3存储桶,然后像其他任何文件一样包含该文件。
根据php上的allow_url_fopen和allow_url_include ini设置,可以使用自定义流包装器实现。 我们在我们的项目中使用了这样的东西。 由于拥有IPR,因此无权共享代码。 但它基于http://docs.aws.amazon.com/aws-sdk-php/v2/guide/feature-s3-stream-wrapper.html
Amazon S3流包装器允许您使用内置的PHP函数(如file_get_contents,fopen,copy,rename,unlink,mkdir,rmdir等)从Amazon S3存储和检索数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.