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

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

WBOY
WBOYOriginal
2016-06-13 10:17:431525Durchsuche

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

 


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn