我怎样才能下载和使用Amazon S3的SDK水桶执行PHP文件?水桶、文件、Amazon、PHP

2023-09-11 10:34:12 作者:满眼的星辰

我怎么能执行一个PHP文件,同时连接一个水桶在使用亚马逊S3 SDK?

How can I execute a PHP file, while connecting a bucket in Amazon using S3 SDK?

我试着用 $ S3-> getBucket ,我得到了下面的数组。但我需要执行这个文件的结果。

I tried with $s3->getBucket, I got the following array. But I need the results of execution of this file.

Array
(
    [content/content.php] => Array
        (
            [name] => content/content.php
            [time] => 1353105202
            [size] => 1223
            [hash] => 355c51389b51814d4b6c822a6ec28cfe
        )

)

有什么功能/方法执行一个PHP文件?

Is there any function/method to execute a PHP file?

推荐答案

您不能执行PHP文件直接在Amazon S3。

You can't execute PHP files directly on Amazon S3.

什么,你必须做的就是下载它的内容,将内容写入到文件中,然后运行该文件本身(通过使用包括()或要求())。

What you would have to do is download it's contents, write the contents to the file, then run the file itself (by using include() or require()).

如果该文件直接输出的东西,你可以用它在ob_start()函数和ob_get_clean()来获取任何输出。

If the file outputs stuff directly, you can wrap it in ob_start() and ob_get_clean() to get any output.

$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.