首頁 > php教程 > php手册 > SAE学习-使用SAE的Storage服务存储图片

SAE学习-使用SAE的Storage服务存储图片

WBOY
發布: 2016-06-13 10:17:43
原創
1562 人瀏覽過

首先看一下SAE的storage服务内容:

 

<span <?<span php
</span><span //</span><span 从SAE的汇总信息拿到这2个key
//属性
//方法</span>
<span function</span> loadImagesByGroupName(<span $directoryname</span><span ) {
    
    </span><span $accessKey</span> = "your app's accessKey"<span ;
    </span><span $secretKey</span> = "your app's secretKey"<span ;
    </span><span $sae_storage</span> = <span new</span> SaeStorage(<span $accessKey</span>, <span $secretKey</span><span );
    </span><span $domainName</span> = "projectimages"<span ;
    </span><span $listfiles</span> = <span $sae_storage</span>->getListByPath(<span $domainName</span>, <span $directoryname</span><span );



    </span><span $files</span> = <span $listfiles</span>["files"<span ];

    </span><span $imageUrls</span> = <span array</span><span ();
    </span><span foreach</span> (<span $files</span> <span as</span> <span $imagefile</span><span ) {
        
        </span><span $tempName</span>=<span $directoryname</span> ."/". <span $imagefile</span>["Name"<span ];
        </span><span $imageUrl</span> = <span $sae_storage</span>->getUrl(<span $domainName</span>, <span $tempName</span><span );
        </span><span array_push</span>(<span $imageUrls</span>, <span $imageUrl</span><span );
    }
    
    </span><span return</span> <span $imageUrls</span><span ;
}
 </span><span //</span><span 测试方法
//try {
//   
//    $result = loadImagesByGroupName("cokegame");
//    print_r($result);
//} catch (Exception $e) {
//    echo "Error:" . $e->getMessage();
//}</span>
?></span>
登入後複製

<span <span require_once</span> 'CustomImage.php'<span ;
</span><ul <span class</span>="itemImageList">
                    <?<span php
                    
                    </span><span $imagesUrls</span>=loadImagesByGroupName("cokegame"<span );
                    </span><span //</span><span 使用for对数组进行循环</span>
                    
                    <span for</span>(<span $i</span>=0;<span $i</span><<span count</span>(<span $imagesUrls</span>);<span $i</span>++<span )
                    {
                        </span>?>
                        <li>
                            <a href="javascript:void(0);" rel=""><img  src=<?php <span echo</span alt="SAE学习-使用SAE的Storage服务存储图片" > <span $imagesUrls</span>[<span $i</span>] ?> alt="Coke Gaming Zone Preview Image"></a>
                        </li>
                    <?<span php   
                        }
                    </span>?>
                <div <span class</span>="clearfix"></div>
            </ul></span>
登入後複製

登入後複製

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板