Php AWSPPSDK2(AWS.phar)不适用于Restler框架
我一直在测试一些使用aws sdk PHP将文件上传到S3存储的PHP脚本。这些脚本在直接从浏览器执行时似乎工作得很好,但在Luracast Restler 3.0中尝试通过API类使用时失败 上载某个虚拟文件的示例脚本如下所示:Php AWSPPSDK2(AWS.phar)不适用于Restler框架,php,rest,amazon-web-services,restler,Php,Rest,Amazon Web Services,Restler,我一直在测试一些使用aws sdk PHP将文件上传到S3存储的PHP脚本。这些脚本在直接从浏览器执行时似乎工作得很好,但在Luracast Restler 3.0中尝试通过API类使用时失败 上载某个虚拟文件的示例脚本如下所示: <?php require_once (dirname(__FILE__) . "/../lib/aws/aws.phar"); use Aws\Common\Aws; use Aws\S3\Enum\CannedAcl; use Aws\S3\Except
<?php
require_once (dirname(__FILE__) . "/../lib/aws/aws.phar");
use Aws\Common\Aws;
use Aws\S3\Enum\CannedAcl;
use Aws\S3\Exception\S3Exception;
use Aws\Common\Enum\Region;
function test(){
// Instantiate an S3 client
$s3 = Aws::factory(array(
'key' => 'key',
'secret' => 'secret',
'region' => Region::EU_WEST_1
))->get('s3');
try {
$s3->putObject(array(
'Bucket' => 'my-bucket',
'Key' => '/test/test.txt',
'Body' => 'example file uploaded from php!',
'ACL' => CannedAcl::PUBLIC_READ
));
} catch (S3Exception $e) {
echo "There was an error uploading the file.\n";
}
}
但是,当从upload.php调用时,代码与完美工作的代码完全相同。我一直在浪费时间试图弄清楚这里发生了什么,但我无法得出任何结论。就像aws php sdk自动加载程序在某些情况下无法正常工作一样
有什么提示吗?这让我耽搁了很长时间 该问题是由设置spl_autoload_unregiste的reslters autoloader引起的 如下所述: 解决问题的一种方法是注释掉vendor/Luracast/Restler/AutoLoader.php中的相关行
public static function thereCanBeOnlyOne() {
if (static::$perfectLoaders === spl_autoload_functions())
return static::$instance;
/*
if (false !== $loaders = spl_autoload_functions())
if (0 < $count = count($loaders))
for ($i = 0, static::$rogueLoaders += $loaders;
$i < $count && false != ($loader = $loaders[$i]);
$i++)
if ($loader !== static::$perfectLoaders[0])
spl_autoload_unregister($loader);
*/
return static::$instance;
}
公共静态函数thereCanBeOnlyOne(){
if(静态::$perfectLoaders===spl\U自动加载函数())
返回静态::$instance;
/*
if(false!=$loaders=spl\u autoload\u函数())
如果(0<$count=计数($loaders))
对于($i=0,静态::$rogueLoaders+=$loaders;
$i<$count&&false!=($loader=$loaders[$i]);
$i++)
if($loader!==static::$perfectLoaders[0])
spl_自动加载_注销($loader);
*/
返回静态::$instance;
}
Fatal error: Class 'Aws\Common\Aws' not found in /var/app/current/util/test.php on line 12
public static function thereCanBeOnlyOne() {
if (static::$perfectLoaders === spl_autoload_functions())
return static::$instance;
/*
if (false !== $loaders = spl_autoload_functions())
if (0 < $count = count($loaders))
for ($i = 0, static::$rogueLoaders += $loaders;
$i < $count && false != ($loader = $loaders[$i]);
$i++)
if ($loader !== static::$perfectLoaders[0])
spl_autoload_unregister($loader);
*/
return static::$instance;
}