V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
444683462
V2EX  ›  问与答

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

  •  
  •   444683462 · 2015-03-20 09:37:05 +08:00 · 1963 次点击
    这是一个创建于 3327 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我用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 ();

    2 条回复    2015-03-20 11:55:12 +08:00
    kisshere
        1
    kisshere  
       2015-03-20 11:08:53 +08:00 via Android
    iPad and iPhone表示你这个头像编辑器有点搞笑,不能识别耶!老老实实用jcrop做头像编辑器吧,当然你如果有我的闲情雅致,对网站做个flash和html5头像上传也可以
    444683462
        2
    444683462  
    OP
       2015-03-20 11:55:12 +08:00
    @kisshere 这个编辑器本来就是为PC的web端设计 我们的使用场景不是移动端 谈不上ipad iphone。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5442 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 09:07 · PVG 17:07 · LAX 02:07 · JFK 05:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.