dongzhucha3999 2016-04-14 05:18
浏览 87

如何在一个存储桶中创建多个文件夹?

//showing an Error (POST only supports one key parameter per request.)//

if i am passing more than one variable in policy it is saying invalid number arguments
<?php

$access_key         = ""; //Access Key
$secret_key         = ""; //Secret Key
$my_bucket          = "99md"; //bucket name
$region             = "ap-southeast-1"; //bucket region
$success_redirect   = 'http://'. $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; //URL to which the client is redirected upon success (currently self) 
$allowd_file_size   = "314573700"; //300 MB allowed Size
$folder=$_POST["query"];

//$key="folder/filename.extension";
//dates
$short_date         = gmdate('Ymd'); //short date
$iso_date           = gmdate("Ymd\THis\Z"); //iso format date
$expiration_date    = gmdate('Y-m-d\TG:i:s\Z', strtotime('+23677890000 hours')); //policy expiration 1 hour from now

If I am passing more than one variable in policy it is saying invalid number arguments
$policy = utf8_encode(json_encode(array(
                    'expiration' => $expiration_date,  
                    'conditions' => array(
                        array('acl' => 'public-read'),  
                        array('bucket' => $my_bucket), 
                        
                        array('success_action_redirect' => $success_redirect),
                        array('starts-with',(array('$key',''))),
                        
                       array('content-length-range', '1', $allowd_file_size), 
                        array('x-amz-credential' => $access_key.'/'.$short_date.'/'.$region.'/s3/aws4_request'),
                        array('x-amz-algorithm' => 'AWS4-HMAC-SHA256'),
                        array('X-amz-date' => $iso_date)
                        )))); 

 
$kDate = hash_hmac('sha256', $short_date, 'AWS4' . $secret_key, true);
$kRegion = hash_hmac('sha256', $region, $kDate, true);
$kService = hash_hmac('sha256', "s3", $kRegion, true);
$kSigning = hash_hmac('sha256', "aws4_request", $kService, true);
$signature = hash_hmac('sha256', base64_encode($policy), $kSigning);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Aws S3 Direct File Uploader</title>
</head>
<body>
<script type="text/javascript">
function submitform()
{
document.forms["myform"].submit(); 
alert("Value is sumitted");
}
</script>

<form id="myform"  method="post">

<table align="center">
<tr CLASS="EVEN">
        <td>
           Choose Store Name
        </td>
        <td style="width: 275px">
             <select name="query"> 
            <option value="" style="text-align:left;"> -----------ALL----------- </option> 
            <?php
            include("db.php");
  
                 $dd_res=mysql_query("select Store_Desc from ret_ticket_install where Supp_Tick_Desc = 'In Process'");
                 while($r=mysql_fetch_array($dd_res))
                 { 
                       echo "<option value='$r[Store_Desc]'> $r[Store_Desc] </option>";
                 }
             ?>
              </select> 
        </td>
    </tr>
</table>
    <table align="center">
        <tr>
            <td>
                <a href="javascript: submitform()">Submit</a>
            </td>
        </tr>
    </table>

</form>

<form action="http://<?= $my_bucket ?>.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
<table align="center">
<tr>
<td>



<input type="hidden" name="key" value="<?=$folder;?>/${filename}";  
</td>
</tr>


<tr>
<td>


<input type="hidden" name="key" value="<?=$folder;?>/MainAdvertisement-Cont1/${filename}" /> //if i am passing more than one variable in policy it is saying invalid number arguments(how to pass)
</td>
</tr>

<input type="hidden" name="acl" value="public-read" />
<input type="hidden" name="X-Amz-Credential" value="<?= $access_key; ?>/<?= $short_date; ?>/<?= $region; ?>/s3/aws4_request" />
<input type="hidden" name="X-Amz-Algorithm" value="AWS4-HMAC-SHA256" />
<input type="hidden" name="X-Amz-Date" value="<?=$iso_date ; ?>" />
<input type="hidden" name="Policy" value="<?=base64_encode($policy); ?>" />
<input type="hidden" name="X-Amz-Signature" value="<?=$signature ?>" />
<input type="hidden" name="success_action_redirect" value="<?= $success_redirect ?>" />  
<tr>
<td>
<input type="file" name="file" />
</td>
</tr>
<tr>

<tr>
<td>
<br><input type="submit" value="Upload File" />
</td>
</tr>

</table>
</form>

<?php
//After success redirection from AWS S3
if(isset($_GET["key"]))
{
    $filename = $_GET["key"];
    $ext = pathinfo($filename, PATHINFO_EXTENSION);
    if(in_array($ext, array("jpg", "png", "gif", "jpeg"))){
        echo '<hr />Image File Uploaded : <br /><img src="http://'.$my_bucket.'.s3.amazonaws.com/'.$_GET["key"].'" style="width:100%;" />';
    }else{
        echo '<hr />File Uploaded : <br /><a href="http://'.$my_bucket.'.s3.amazonaws.com/'.$_GET["key"].'">'.$filename.'</a>';
    }
}
?>
</body>
</html>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度