Discuz教程网

Sina App Engine--使用Storage存储上传文件

[复制链接]
authicon 1314学习网 发表于 2011-6-24 16:36:08 | 显示全部楼层 |阅读模式
Storage是SAE(Sina App Engine)为开发者提供的分布式文件存储服务,用来存放用户的持久化存储的文件。用户需要先在在线管理平台创建Domain(相当于一级子目录),创建完毕后,可以通过两种方式操作其中数据:
   1,通过SDK GUI操作,具体参考SDK => 工具
   2,通过sae_std_lib下的SaeStor的API读写Storage
这里主要介绍的是第二种方法。
下面是一个上传文件的页面:

Html代码
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  4. <title>上传文件</title>
  5. </head>
  6. <body>
  7. <p><a href="listfiles.php" target="_blank">所有文件</a></p>
  8. <form enctype="multipart/form-data" action="upload.php" method="post">
  9. <input name='myfile' type='file'/>
  10. <input type="submit" value="上传"/>
  11. </form>
  12. </body>
  13. </html>
复制代码

接下来是upload.php的内容:


Php代码
  1. <?php
  2. $s2 = new SaeStorage();
  3. $name =$_FILES['myfile']['name'];

  4. echo $s2->upload('test',$name,$_FILES['myfile']['tmp_name']);//把用户传到SAE的文件转存到名为test的storage
  5. // echo $s2->getUrl("test",$name);//输出文件在storage的访问路径
  6. echo '<br/>';
  7. echo $s2->errmsg(); //输出storage的返回信息
  8. ?>
复制代码

其中:
string upload (string $domain, string $destFile, string $srcFile, [array $attr = array()], [bool $compress = false])
将文件上传入存储

string getUrl (string $domain, string $filename)
取得访问存储文件的url

Sina App Engine现可开10个应用,支持最多10个Domain,单个应用最多5个Domain,单个Domain最大2G.




上一篇:让Discuz X2版块规则,支持HTML
下一篇:windows2003+iis6+php(fastcgi)5.3+wincache+memcache环境配置架设过程
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 21:49

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表