亚马逊S3上传失败 [英] Amazon s3 upload fail

查看:994
本文介绍了亚马逊S3上传失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做一些code提交上传的图片从C#到PHP,然后存储在Amazon S3的形象,我已经得到尽可能我一直想它上传到本地主机,而我只是不能把它上传到Amazon S3。只是想知道,如果你们能够给我一点帮助?不用担心,如果你不愿意。

I have been working on some code to submit an uploaded image to PHP from C# and then storing the image on Amazon S3, I have got as far as I have wanted uploading it to localhost, but I'm just unable to upload it to Amazon S3. Just wondering if you guys can give me a little help? No worries if your not willing to.

我使用的是发现这里的Amazon S3的PHP类

下面是我的code。

<?php

if (!class_exists('S3'))require_once('S3.php');
if (!defined('awsAccessKey')) define('awsAccessKey', 'CHANGEME');
if (!defined('awsSecretKey')) define('awsSecretKey', 'CHANGEME');
$s3 = new S3(awsAccessKey, awsSecretKey);





$uploaddir = 'upload/'; // Relative Upload Location of data file
$random_digit=rand(0000,9999); // random 4 digit to add to our file name 
$nextWeek = time() + (7 * 24 * 60 * 60); //Gets system time.
$counter = 1;
if (is_uploaded_file($_FILES['file']['tmp_name']))
{
    if(strpos(basename($_FILES['file']['name']), ".")){
    $s1 = explode(".", basename($_FILES['file']['name']));
    $p1 = count($s1) - 2;
    $p2 = count($s1) - 1;

    $uploadfile = $uploaddir . $s1[$p1] . $random_digit . $nextWeek  . "." .    $s1[$p2];
    $s3->putObjectFile($uploadfile, "bucketname", $uploadfile, S3::ACL_PUBLIC_READ);
} 
else 
    {
    $uploadfile = $uploaddir . basename($_FILES['file']['name']) .  $random_digit . $nextWeek ;
    $s3->putObjectFile($uploadfile, "bucketname", $uploadfile, S3::ACL_PUBLIC_READ);
    }
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
{
    $url = explode("/", $uploadfile);
    echo $url[1];
}
else
    {
        print_r($_FILES);
    }

}

else {

echo "Upload Failed!!!";

print_r($_FILES);
}

?>

这两条线的code已经在开始 $ uploadfile

推荐答案

请在下面找到...

if (!class_exists('S3'))require_once('S3.php');
if (!defined('awsAccessKey')) define('awsAccessKey', 'CHANGEME');
if (!defined('awsSecretKey')) define('awsSecretKey', 'CHANGEME');
$s3 = new S3(awsAccessKey, awsSecretKey);

$fileName = $_FILES['theFile']['name'];
$fileTempName = $_FILES['theFile']['tmp_name'];

$s3->putBucket("Bucket Name", S3::ACL_PUBLIC_READ);

if ($s3->putObjectFile($fileTempName, "Bucket Name", $fileName, S3::ACL_PUBLIC_READ)) {
    echo "We successfully uploaded your file.";
}else{  
    echo "Something went wrong while uploading your file... sorry.";
}

这篇关于亚马逊S3上传失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆