首页 课程中心 问答&分享 读书 公众号框架 HUI H.JS 开放源 登录 & 注册
 我上传头像我php写好了怎么不行
[ xx ] 发布于 : 2018-05-15  浏览 :  次
<?php
/**
 * @version        $Id: edit_face.php 1 8:38 2010年7月9日Z tianya $
 * @package        DedeCMS.Member
 * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
 * @license        http://help.dedecms.com/usersguide/license.html
 * @link           http://www.dedecms.com
 */
require_once(dirname(__FILE__)."/config.php");

/*    $files = $_POST['face'];    //获取压缩图片
    $temp = substr($files, 22);    //去除压缩图片文件头  [data:image/jpg;base64]
    $face = base64_decode($temp);     //解释压缩图片*/

CheckRank(0,0);
$menutype = 'config';
if(!isset($dopost))
{
    $dopost = '';
}
if(!isset($backurl))
{
    $backurl = 'tx.php';
}
if($dopost=='save')
{
    $maxlength = $cfg_max_face * 1024;
    $userdir = $cfg_user_dir.'/'.$cfg_ml->M_ID;
    if(!preg_match("#^".$userdir."#", $oldface))
    {
        $oldface = '';
    }
    if(is_uploaded_file($face))
    {
        if(@filesize($_FILES['face']['tmp_name']) > $maxlength)
        {
            //ShowMsg("你上传的头像文件超过了系统限制大小:{$cfg_max_face} K!", '-1');
            die("1");
            exit();
        }
        //删除旧图片(防止文件扩展名不同,如:原来的是gif,后来的是jpg)
        if(preg_match("#\.(jpg|gif|png)$#i", $oldface) && file_exists($cfg_basedir.$oldface))
        {
            @unlink($cfg_basedir.$oldface);
        }
        //上传新工图片
        $face = MemberUploads('face', $oldface, $cfg_ml->M_ID, 'image', 'myface', 180, 180);
    }
    else
    {
        $face = $oldface;
    }
    $query = "UPDATE `#@__member` SET `face` = '$face' WHERE mid='{$cfg_ml->M_ID}' ";
    $dsql->ExecuteNoneQuery($query);
         //2013年7月增加头像添加增加10积分。
 if(empty($oldface)){
   $dsql->ExecuteNoneQuery("UPDATE `#@__member` set scores=scores+{$cfg_face_adds} WHERE mid='".$cfg_ml->M_ID."' ; ");
  $mtime = time();
  $inquery = "INSERT INTO `#@__member_operation`(`buyid` , `pname` , `product` , `money` , `mtime` , `pid` , `mid` , `sta` ,`oldinfo`)
              VALUES (' ', '上传头像', 'ddss' , '{$cfg_face_adds}' , '$mtime' , '0' , '{$cfg_ml->M_ID}' , '1' , ''); ";
  $dsql->ExecuteNoneQuery($inquery);   
  }
    // 清除缓存
    $cfg_ml->DelCache($cfg_ml->M_ID);
    /*ShowMsg('成功更新头像信息!', $backurl);*/
    echo $face;
    
    
    exit();
}
$face = $cfg_ml->fields['face'];

exit();
?>

这个是我的php代码

下面是js的

mui(".tou-tx").on("tap", "#head", function(e) {
if (mui.os.plus) {
var a = [{
title: "拍照"
}, {
title: "从手机相册选择"
}];
plus.nativeUI.actionSheet({
title: "修改用户头像",
cancel: "取消",
buttons: a
}, function(b) { /*actionSheet 按钮点击事件*/
switch (b.index) {
case 0:
break;
case 1:
getImage(); /*拍照*/
break;
case 2:
galleryImg();/*打开相册*/
break;
default:
break;
}
})
}
});

function getImage(){
var cmr = plus.camera.getCamera();
cmr.captureImage( function ( p ) {
//成功
plus.io.resolveLocalFileSystemURL( p, function ( entry ) {

var img_name = entry.name;//获得图片名称
var img_path = entry.toLocalURL();//获得图片路径
upload_img(img_path);
}, function ( e ) {
console.log( "读取拍照文件错误:"+e.message );
} );

}, function ( e ) {
console.log( "失败:"+e.message );
}, {filename:'_doc/camera/',index:1} ); // “_doc/camera/“ 为保存文件名

}
function galleryImg(){
plus.gallery.pick( function(path){

//img.src = path;//获得图片路径
upload_img(path);
}, function ( e ) {
console.log( "取消选择图片" );
}, {filter:"image"} );

}


//初始上传地址
function upload_img(p){
//alert(p);
var task = plus.uploader.createUpload(
'http://www.222222.com/member/tx2.php',
{ method:"POST"},
function (t,status){
console.log(JSON.stringify(t));
console.log(status);
}

);
for(i in paths.files){

task.addFile(paths.files[i],{key:'uper'+i,'name':paths.files[i].substr(paths.files[i].lastIndexOf('/'))});
}
task.start();
}


哪个朋友个看看

教程更新
More...