新浪SAE官方地址:http://apidoc.sinaapp.com/sae/SaeStorage.html
SaeStorage的代码详细:http://apidoc.sinaapp.com/__filesource/fsource_sae__saestorage.class.php.html
SAE官方给出的示例:
<?php $s = new SaeStorage(); $s->upload( ‘example‘ , ‘remote_file.txt‘ , ‘local_file.txt‘ ); echo $s->read( ‘example‘ , ‘thebook‘) ; // will echo ‘bookcontent!‘; echo $s->getUrl( ‘example‘ , ‘thebook‘ ); // will echo ‘http://appname-example.stor.sinaapp.com/thebook‘; ?>
index.php负责上传图片,post到upload.php进行操作,首先判断是否上传成功,然后判断时候为图片,然后进行上传操作,
其实核心代码只有三行:
<?php $s = new SaeStorage(); $s->upload( ‘example‘ , ‘remote_file.txt‘ , ‘local_file.txt‘ ); $s->getUrl( ‘example‘ , ‘thebook‘ );
<html> <body> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html>
<?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { //文件成功上传到SAE的临时服务器中 $file_name = $_FILES["file"]["name"]; $type = $_FILES["file"]["type"]; $size = ($_FILES["file"]["size"] / 1024)." Kb"; $temp_stored = $_FILES["file"]["tmp_name"]; $valid_type = "..image/pjpeg,image/gif,image/jpeg,image/bmp,image/png"; if(strpos($valid_type,$type)) {//上传的是图片文件 $s = new SaeStorage(); $src_name = $temp_stored; $des_name = urlencode($file_name); $s->upload( ‘qianshou‘ , "$des_name" , "$src_name" ); $url = $s->getUrl( ‘qianshou‘ , "$des_name" ); echo "<img src=\"$url\" />"; echo "<br/>".$s->errmsg(); } else { echo $type."is invalid.<br/>"; } } ?>
SaeStorage使用示例,码迷,mamicode.com
原文地址:http://blog.csdn.net/qsyzb/article/details/24672885