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

xxx织梦者
  • 1.9k

我用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 ();
回复
阅读 4k
1 个回答

是不是没上传有一个跨域的xml