| Storage是SAE(Sina App Engine)为开发者提供的分布式文件存储服务,用来存放用户的持久化存储的文件。用户需要先在在线管理平台创建Domain(相当于一级子目录),创建完毕后,可以通过两种方式操作其中数据: 1,通过SDK GUI操作,具体参考SDK => 工具
 2,通过sae_std_lib下的SaeStor的API读写Storage
 这里主要介绍的是第二种方法。
 下面是一个上传文件的页面:
 
 Html代码
 复制代码<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>上传文件</title>
</head>
<body>
<p><a href="listfiles.php" target="_blank">所有文件</a></p>
<form enctype="multipart/form-data" action="upload.php" method="post">
<input name='myfile' type='file'/>
<input type="submit" value="上传"/>
</form>
</body>
</html>
接下来是upload.php的内容:
 
 
 Php代码
 复制代码<?php
$s2 = new SaeStorage();
$name =$_FILES['myfile']['name'];
echo $s2->upload('test',$name,$_FILES['myfile']['tmp_name']);//把用户传到SAE的文件转存到名为test的storage
// echo $s2->getUrl("test",$name);//输出文件在storage的访问路径
echo '<br/>';
echo $s2->errmsg(); //输出storage的返回信息 
?>
其中:
 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.
 
 
 |