• 上传图片到PHP服务器


    test_picture = function() {
                api.getPicture({
                        sourceType: 'library',
                        encodingType: 'png',
                        mediaValue: 'pic',
                        destinationType: 'url',
                        allowEdit: true,
                        //quality: 50,
                        //targetWidth:100,
                        //targetHeight:100,
                        saveToPhotoAlbum: false
                    }, function(ret, err){ 
                        if (ret) {
                         api.ajax({
                      timeout : 100,
                      method : 'post',
                      url : 'http://192.168.1.121/picture.php',
                      data : {
                              files:{upfile : ret.data},
                      },
                      dataType : 'json',
                  }, function(ret, err) {
                      api.hideProgress();
                      alert(JSON.stringify(ret));
                  });
                        } else {
                            api.alert({msg:err.msg});
                        };
                    });
        };
    
    
    
    PHP接收图片
    <?php
    function getname($exname){
            $dir = "./uploadfile/";
               $i=1;
               if(!is_dir($dir)){
                  mkdir($dir,0777);
               }
               while(true){
                if(!is_file($dir.$i.".".$exname)){
                    $name=$i.".".$exname;
                    break;
                  }
                 $i++;
               }
               return $dir.$name;
    }
    
    
    $exname=strtolower(substr($_FILES['upfile']['name'],(strrpos($_FILES['upfile']['name'],'.')+1)));
    
    $uploadfile = getname($exname); 
    
    
    if (move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile)) {
    
       echo "<h2><font color=#ff0000>文件上传成功!</font></h2><br><br>";
    
    } else {
    
       echo "<h2><font color=#ff0000>文件上传失败!</font></h2><br><br>";
    
    }
    ?>
  • 相关阅读:
    TortoiseGit保存用户名密码的方法
    nginx proxy优化
    tomcat优化
    mongodb 慢SQL查询
    iptables基础知识
    mongostat
    mongodb命令
    nginx libpcre.so.1: cannot open shared object file
    error while loading shared libraries: libmcrypt.so.4
    mongodb常见问题
  • 原文地址:https://www.cnblogs.com/haonanZhang/p/6733346.html
Copyright © 2020-2023  润新知