新浪sae上面如何上传图片(PHP)

废话不多说,直接重点

在新浪storage下面创建一个domain,名字叫什么随便,我的叫test

能收到这篇文章的人,估计下面的不解释了

 

<html>
  <head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <title>上传测试</title>
  </head>
  <body>
  	<form id="form1" name="form1" method="post" action="newpost.php" enctype="multipart/form-data">
          图片:<input type="file" name="photo" />
          <input type="submit" value="提交" />
    	</form>
  </body>
</html>


下面要做的就是new一个SaeStorage();对象,然后步骤1,更改文件名字,存入,拿出URL,根据URL访问图片,完了

 

为了增长文章长度,把新浪的这个对象的方法全部copy过来

 

PHP调用方式

 

 

使用指南

 创建domain

    用户需要先创建一个Domain,在线管理平台=>服务管理=>Storage,输入Domain名称,创建一个Domain

 删除domain

    在线管理平台=>服务管理=>Storage,确认删除某个Domain

 GUI操作

    请参考,http://sae.sina.com.cn/?m=devcenter&catId=29#anchor_c267049d9b7e52eeb331ec37381812be

 Storage API操作

    目前Storage提供以下的函数支持:

  void __construct ([string $_accessKey = ''], [string $_secretKey = ''])

  bool delete (string $domain, string $filename)

  string errmsg ()

  int errno ()

 

  bool fileExists (string $domain, string $filename)

    检查文件是否存在

 

  array getAttr (string $domain, string $filename, [array $attrKey = array()])

    获取文件属性

 

  array getList (string $domain, [string $prefix = '*'], [int $limit = 10], [int $skip = 0])

    获取指定domain下的文件名列表

 

  string getUrl (string $domain, string $filename)

    取得访问存储文件的url

 

  mixxed read (string $domain, string $filename)

    获取文件的内容

 

  void setAuth (string $akey, string $skey)

    设置key

 

  bool setDomainAttr (string $domain, [array $attr = array()])

    设置Domain属性

 

  bool setFileAttr (string $domain, string $filename, [array $attr = array()])

    设置文件属性

 

  string upload (string $domain, string $destFile, string $srcFile, [array $attr = array()],

  [bool $compress = false])

    将文件上传入存储

 

  string write (string $domain, string $destFile, string $content, [int $size = -1], [array

  $attr = array()], [bool $compress = false])

    将数据写入存储

 

    具体的使用说明请参考,http://apidoc.sinaapp.com/sae/SaeStorage.html

cpoy完毕,贴我自己的代码

 

<?php


文件名叫newpost.php
function backImageUrl($photo){
  $typearr = array("image/jpeg","image/jpg","image/pjpeg","image/gif","image/bmp");

  if(!in_array($photo["type"],$typearr)){
    header("Content-Type:text/html;charset=UTF-8");
    $url = @$_SERVER["HTTP_REFERER"];
    header("refresh:3;url={$url}");
    exit("上传格式只能是jpeg,jpg,pjpeg,gif,bmp");
  }

  $suffixname = strrchr($photo["name"],'.');
  $s = new SaeStorage();
  $s->upload( 'test' ,$photo["tmp_name"].$suffixname,$photo["tmp_name"] );
  $erjin  = $s->read( 'test' ,$photo["tmp_name"]) ;
  return $s->getUrl( 'test' ,$photo["tmp_name"]).$suffixname;
}
echo backImageUrl($_FILES["photo"]);
?>

 

 

 

 

 

m.kuanggouli.cn  推广返充值

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值