最新消息:本站访问过程中有任何问题请与我联系……

【PHP】新浪云SAE平台将本地图片和远程图片保存至Storage

程序源码 xx2008 4804浏览 0评论

最近在弄一个购物分享的程序(http://ganhuo.xxorg.com),因为这个程序放在新浪云SAE平台,图片需要存储在新浪云SAE平台的Storage,所以找到了在新浪云SAE平台将本地图片和远程图片保存至Storage的最简洁的方法,现在给大家分享一下 :

一、远程图片保存至Storage 

<?php
$s = new SaeStorage();
$img = file_get_contents('http://www.asitela.com/shopbg.png');  //括号中的为远程图片地址
$s->write ( 'public' ,  'b.png' , $img );    
?>
  // 【public】为 Storage的名称;【b.png】为图片名称,格式可以自己任意设置格式,改成b.png均能正常显示,且大小不变;

二、本地图片上传至Storage 

【提交页面】

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="container">
<form action="upload.php" method="post" enctype="multipart/form-data">
<p><input type="file" name="filename" /></p>
<input type="submit"  id="postBtn" value="上传图片">
</form>  
</div>
</body>
</html>

【处理页面】

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>图片上传处理代码</title>
</head>
<body>

<?php
$filename = 'filename';
$files = $_FILES[$filename];
$name= 'asitela-'.time().'.jpg';
$form_data =$files['tmp_name'];
$s2 = new SaeStorage();
$img = new SaeImage();
$img_data = file_get_contents($form_data);//获取本地上传的图片数据
$img->setData($img_data);
$img->resize(180,180); //图片缩放为180*180
$img->improve();//提高图片质量的函数
$new_data = $img->exec(); // 执行处理并返回处理后的二进制数据
$s2->write('public',$name,$new_data);//将public修改为自己的storage 名称$url= $s2->getUrl('public',$name);//将public修改为自己的storage 名称echo "文件名:".$name."<br/>";
echo "图片url:".$url."<br/>";
echo "<img src='$url' />";
?>
</body>
</html>

转载请注明:服务器VPS折腾 » 【PHP】新浪云SAE平台将本地图片和远程图片保存至Storage

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (9)

  1. Anon, it´s a pity you did not think of an interesting nick. I wanted to use your remark about the shot from the bow as a signature, if that´s alright with you. Only now I have no choice but to put ´Anonymous´ as source..Won´t you try and find something more inventive?
  2. Tu me donnes tellement envie avec tes fruits!! Je n’ai pas le temps de faire des courses en ce moment et je manque atrocement de fruits dans ma cuisine (enfin… dans le mètre carré qui me sert de cuisine ^^ )…
  3. E secondo voi se il governo cinese fossse stato veramente preoccupato dell'oggetto non identificato, non avrebbe inviato neanche un aereo ad ispezionare i cieli ?!? Già mi immagino la scena dell'aereo militare che si avvicina e viene distrutto dallo scudo spaziale della navicella ehehe 😛
    auto insurance2016-06-05 16:22 回复
  4. excellent issues altogether, you simply received a brand new reader. What might you recommend about your post that you just made some days in the past? Any sure?
  5. Gerd Hallo Flavio,dies war mal wichtig zu wissen! Damit lässt man sich auch nicht so von der Werbung von Proteinprodukten blenden, wie: “BW 128″, wobei dies mit der Kombi von minderwertigem Weizenprotein erreicht wird.Deine Erklärungen helfen mir jetzt, hochwertige Produkte zu erkennen.Vielen Dank!Gruß Gerd
  6. here but it keeps not happening. Meantime, here’s some more shameless self promotion. Episode 32 of Awesome Friday, in which we discuss our top ten games from the 6th generation. Share and Enjoy This entry was
  7. Tenafly Comp Killer!2635400 SoldSLD 6 SISSON TER $2,800,000 6/2/2007 Wha?2723528 ExpiredACT 6 SISSON TER $2,850,000 6/8/2007PCH 6 SISSON TER $2,775,000 10/18/2007PCH 6 SISSON TER $2,690,888 11/7/2007EXP 6 SISSON TER $2,690,888 12/8/20072748124 SoldACT 6 SISSON TER $2,649,500 12/10/2007ACT* 6 SISSON TER $2,649,500 5/6/2008U/C 6 SISSON TER $2,649,500 5/27/2008SLD 6 SISSON TER $2,350,000 6/5/2008
  8. “In recent years, some mainstream news sources, including the MiamiHerald and the San Antonio News-Express, have stopped using the term while others, like the Associated Press and The New York Times, have refused to drop the term.”LOL. So you Daily idiots think you’re better than the Associated Press and the LIBERAL New York Times? Stupid narcissists, all of you on the Senior Editorial Board.
  9. That's a crackerjack answer to an interesting question