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

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

WBOY
发布: 2016-06-13 10:17:43
原创
1552 人浏览过

首先看一下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
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板