zoukankan      html  css  js  c++  java
  • SAE云平台上传图片和发送邮件

     

    1.远程图片保存至Storage

      其中public是Storage中的容器名,"目录1/目录2/"是容器下的路径 $file_content 是得到的文件数据

    1 $s = new SaeStorage();
    2 $file_content= file_get_contents('http://abc.pmg');   //括号中的为远程图片地址
    3 $s->write ( 'public' ,  '目录1/目录2/abc.png' , $file_content); 
        
    2.sae上的上传图片
       用thinkphp框架内置上传类能够完美兼容sae环境,只是在sae上上传成功后返回的路    径是文件名,需要手动加上上传的容器路径,即在项目中需要替换__ING__或者是__PUBLIC__    的路径,得到路径的方法如下:
    1 $storage = new SaeStorage();                      //实例化SaeStorage类
    2 $uploadsae = $storage->getUrl('public','Upload');  //得到sae的上传容器路径 
     其中public是Storage中的容器名,"Upload"是容器下的路径;
     替换方法可采用tp的模板替换方法:
    
    1 'TMPL_PARSE_STRING'    =>    array(
    2      '__ING__'    => $st->getUrl('public','upload'),
    3      '__PUBLIC__' => $st->getUrl('application','user')
    4 
    5 )

     

    3:生成缩略图并保存在相应的容器中

       如果用tp的生成缩略图方法也可以在sae上成功运行,下面使用sae提供的方法生成缩略图
     1 $f = new SaeFetchurl();
     2 $img_data = $f->fetch(“图片url”); //有文件名读取文件
     3 $img = new SaeImage();
     4 $img->setData($img_data);
     5 $img->resize($width,$height);    //指定缩略图的宽和高
     6 $new_data = $img->exec();        //执行处理并返回处理后的二进制数据
     7 if ($new_data === false){        //图片处理失败时输出错误
     8         return false;
     9 }
    10 $s->write ( 'public' , '目录1/目录2/abc.png' , $file_content);
    11 $img->exec( 'jpg' , true );  //如果不想保存,而是想输出则用:

    4:不带html的邮件(不支持html)
    1 $mail = new SaeMail();
    2 $body = "亲爱的用户:感谢您在在本网站注册了新帐号。请点击链接激活您的帐号"3 $mail->setAttach(array("my_photo"=>"照片的二进制数据"));//如果发送图片
    4 $ret = $mail->quickSend("收件人的邮箱", '邮件标题' , $body , '发送人的邮箱' , '发送人邮箱密码','smtp.139.com',25); //smtp.139.com是主机号,25是SMTP服务器端口
    5 $mail->clean();     //清楚之前的对象用于循环发送

     

    5:带html的邮件(支持html)

           其中setOpt()只在send()发送命令中起作用,在快速发送quickSend()中不起作用;

     1 $mail = new SaeMail();
     2 $mail->setOpt(array(
     3      'from'          => 'abc@sina.com', //发件邮箱例如abc@sina.com
     4      'to'            => $data['email'],      //接收信箱  
     5      'smtp_host'     => 'smtp.139.com',  //smtp服务器
     6      'smtp_port'     => 25,  //port
     7      'smtp_username' => 'abc@sina.com', //账户全名,abc@sina.com,要和上面的一样
     8      'smtp_password' => '发送邮箱吗密码',
     9      'subject'       => '标题',
    10      'content'       => $body, //发送内容
    11      'content_type'  => 'html'   //发送格式,默认是text
    12      )
    13 );
    14 $ret = $mail->send();
    15 $mail->clean();
    16 if($ret == false){
    17       var_dump($mail->errno(), $mail->errmsg()); //打印出错信息
    18       return false;
    19 }else{
    20       return true;
    21 }

    想要了解跟多参数:http://apidoc.sinaapp.com/class-SaeMail.html

  • 相关阅读:
    Oracle 删表前验证表名是否存在并且删除
    Mysql的建表规范与注意事项
    MYSQL总结之sql语句大全
    主机屋云服务器(绑定域名)初探
    (十)Thymeleaf用法——Themeleaf内联
    (九)Thymeleaf用法——Themeleaf注释
    (八)Thymeleaf的 th:* 属性之—— 模板布局& th:with& 属性优先级
    (七)Thymeleaf的 th:* 属性之—— th: ->设值& 遍历迭代& 条件判断
    (六)Thymeleaf的 th:* 属性之—— th: ->text& utext& href
    (五)Thymeleaf标准表达式之——[7->8]条件表达式& 默认表达式
  • 原文地址:https://www.cnblogs.com/zyf-zhaoyafei/p/4373665.html
Copyright © 2011-2022 走看看