>  기사  >  php教程  >  SAE学习-使用SAE的Storage服务存储图片

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

WBOY
WBOY원래의
2016-06-13 10:17:431521검색

首先看一下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>

 


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.