<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <html> <head> <title>ZwelL图片上传程序</title> </head> <form enctype="multipart/form-data" method="post" name="upform"> <input name="upfile" type="file"> <input type="submit" value="上传"> </form> <?php function Outputsmallimage($src,$w,$smallscr) { $temp=pathinfo($src); $name=$smallscr;//文件名 $dir=$temp["dirname"];//文件所在的文件夹 $extension=$temp["extension"];//文件扩展名 $savepath="Smallimages/{$name}";//缩略图保存路径,新的文件名为*.thumb.jpg $info=getimagesize($src); $width=$info[0];//获取图片宽度 $height=$info[1];//获取图片高度 $type=$info[2]; switch($type){ case 1:$im=imagecreatefromgif($src);break; case 2:$im=imagecreatefromjpeg($src);break; case 3:$im=imagecreatefrompng($src);break; default:break; } if ($w == 385) {//此处是对缩略图的比例调整,也可自己定义规则 $h = 500; } elseif ($w == 225) { $h = 300; } elseif ($w == 75) { $h = 100; } $temp_img=imagecreatetruecolor($w,$h);//创建画布 imagecopyresized($temp_img,$im,0,0,0,0,$w,$h,$width,$height); $s = new SaeStorage(); ob_start(); imagejpeg($temp_img); $imgstr = ob_get_contents(); $s->write(‘image1234‘,$savepath,$imgstr); ob_end_clean(); imagedestroy($im); return "saestor://image1234/".$savepath; }
function create_guid() { $charid = strtoupper(md5(uniqid(mt_rand(), true))); $hyphen = chr(45);// "-" $uuid = substr($charid, 0, 8) .substr($charid, 8, 4) .substr($charid,12, 4) .substr($charid,16, 4) ; return $uuid;}
if ($_SERVER[‘REQUEST_METHOD‘] == ‘POST‘) { echo "\n上传开始时间:".date(‘y-m-d h:i:s‘,time())."\n"; $destination_folder="saestor://image1234/Updateimg/"; //上传文件路径 需要在新浪云上创建Storage $file = $_FILES["upfile"]; $filename=$file["tmp_name"]; $image_size = getimagesize($filename); $pinfo=pathinfo($file["name"]); $ftype=$pinfo[‘extension‘]; $imagebig=create_guid().".".$ftype; $imagesmall=create_guid().".".$ftype; $bucket = "w376161501"; $object="Ionic/Imagebig/".$imagebig; try{ if(move_uploaded_file ($filename, $destination_folder.$imagebig))//参数为文件流和存储的位置以及名称 { echo "原图片上传成功"; }
$path=Outputsmallimage($filename,225,$imagesmall); } catch (OssException $e) { echo $e; } //unlink($path); 用于删除缩略图 } ?> </body> </html>
*新浪云上imagegif不支持Wrapper,即imageif,imagejpeg,imagepan不适应了。需要写到缓冲区ob_start();再通过saestorage写入stor
*需要在新浪云上申请Storage(免费)
另一种方法参考链接:http://blog.csdn.net/yangyun_1999/article/details/20377989#comments
其他新浪云应用的文件读写:http://blog.csdn.net/liuqiyao_01/article/details/8551274(参考价值比较大)
时间: 2024-10-05 05:07:37