美图秀秀头像编辑器的使用? thinkphp+七牛方案

2015-03-20 09:37:05 +08:00
 444683462

我用thinkphp,上传到七牛。下面是官方的一个html和一个接口
搞了半天 ,一天头绪都没有,请指教一下大概的方案

这里是html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>美图WEB开放平台</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://open.web.meitu.com/sources/xiuxiu.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload=function(){
/第1个参数是加载编辑器div容器,第2个参数是编辑器类型,第3个参数是div容器宽,第4个参数是div容器高/
xiuxiu.embedSWF("altContent",5,"100%","100%");
//修改为您自己的图片上传接口
xiuxiu.setUploadURL("APP/Home/Home/Staff/uploadHead");
xiuxiu.setUploadType(2);
xiuxiu.setUploadDataFieldName("upload_file");
xiuxiu.onInit = function ()
{
xiuxiu.loadPhoto("http://open.web.meitu.com/sources/images/1.jpg");
}
xiuxiu.onUploadResponse = function (data)
{
alert("上传响应" + data);
}
}
</script>
<style type="text/css">
html, body { height:100%; overflow:hidden; }
body { margin:0; }
</style>
</head>
<body>
<div id="altContent">
<h1>美图秀秀</h1>
</div>
</body>
</html>
这里是官方的处理接口

<?php

/**
* Note:for multipart/form-data upload
* 这个是标准表单上传PHP文件
* Please be amended accordingly based on the actual situation
*/
if (!$FILES['Filedata']) {
die ( 'Image data not detected!' );
}
if ($_FILES['Filedata']['error'] > 0) {
switch ($_FILES ['Filedata'] ['error']) {
case 1 :
$error_log = 'The file is bigger than this PHP installation allows';
break;
case 2 :
$error_log = 'The file is bigger than this form allows';
break;
case 3 :
$error_log = 'Only part of the file was uploaded';
break;
case 4 :
$error_log = 'No file was uploaded';
break;
default :
break;
}
die ( 'upload error:' . $error_log );
} else {
$img_data = $_FILES['Filedata']['tmp_name'];
$size = getimagesize($img_data);
$file_type = $size['mime'];
if (!in_array($file_type, array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/gif'))) {
$error_log = 'only allow jpg,png,gif';
die ( 'upload error:' . $error_log );
}
switch($file_type) {
case 'image/jpg' :
case 'image/jpeg' :
case 'image/pjpeg' :
$extension = 'jpg';
break;
case 'image/png' :
$extension = 'png';
break;
case 'image/gif' :
$extension = 'gif';
break;
}

}
if (!is_file($img_data)) {
die ( 'Image upload error!' );
}
//图片保存路径,默认保存在该代码所在目录(可根据实际需求修改保存路径)
$save_path = dirname( __PUBLIC
_ );
$uinqid = uniqid();
$filename = $save_path . '/' . $uinqid . '.' . $extension;
$result = move_uploaded_file( $img_data, $filename );
if ( ! $result || ! is_file( $filename ) ) {
die ( 'Image upload error!' );
}
echo 'Image data save successed,file:' . $filename;
exit ();

1966 次点击
所在节点    问与答
2 条回复
kisshere
2015-03-20 11:08:53 +08:00
iPad and iPhone表示你这个头像编辑器有点搞笑,不能识别耶!老老实实用jcrop做头像编辑器吧,当然你如果有我的闲情雅致,对网站做个flash和html5头像上传也可以
444683462
2015-03-20 11:55:12 +08:00
@kisshere 这个编辑器本来就是为PC的web端设计 我们的使用场景不是移动端 谈不上ipad iphone。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/178144

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX