|
本帖最后由 洛沂雪夜 于 2015-12-30 17:22 编辑
前端还是从这个大神的帖子里拿的http://bbs.wex5.com/thread-68669-1-1.html这里的图片上传附件里
JS端
- define(function(require) {
- var $ = require("jquery");
- var justep = require("$UI/system/lib/justep");
- var Baas = require("$UI/demo/baas/baas");
- var Model = function() {
- this.callParent();
- };
- Model.prototype.uploadImage = function(imageURI) {
- var me = this;
- var options = new FileUploadOptions();
- options.fileKey = "fileAddPic";// 用于设置参数
- options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
- // 如果是图片格式,就用image/jpeg,其他文件格式上官网查API
- options.mimeType = "image/jpeg";
- // 这里的uri根据自己的需求设定,是一个接收上传图片的地址
- var uri = encodeURI("http://192.168.20.16/svnidc/APP/Ceshi/test");
- options.chunkedMode = false;
- var params = new Object();
- params.id = "1";
- params.name = "test";
- options.params = params;
- var ft = new FileTransfer();
- function success(asdfghjkl) {
- alert(JSON.stringify(asdfghjkl));
- navigator.notification.progressStop();
- me.button1Click(options.fileName);
- }
- function fail(message) {
- alert('4');
- alert("失败:" + JSON.stringify(message));
- }
- // 上传回调
- ft.onprogress = showUploadingProgress;
- navigator.notification.progressStart("", "当前上传进度");
- ft.upload(imageURI, uri, success, fail, options);
- };
- // 显示上传进度
- function showUploadingProgress(progressEvt) {
- if (progressEvt.lengthComputable) {
- navigator.notification.progressValue(Math.round((progressEvt.loaded / progressEvt.total) * 100));
- }
- }
- Model.prototype.a1Click = function(event) {
- event.currentTarget.parentNode.remove();
- };
- Model.prototype.button3Click = function(event) {
- this.comp("popOver2").show();
- };
- Model.prototype.image1Click = function(event) {
- var me = this;
- window.closeP = function() {
- me.closeP();
- };
- var src = event.currentTarget.currentSrc;
- var img = $("<a href='javascript:closeP()' style='position: absolute;top:10px;'>关闭</a><img src='" + src + "'/>");
- $(".img_content").contents().remove();
- justep.Bind.addNodes(this.getElementByXid("div2"), img);
- this.comp("popOver1").show();
- // this.comp("windowDialog1").open({
- // src : "$UI/uploadImage/viewImage.w",
- // data : img
- // })
- };
- Model.prototype.closeP = function() {
- this.comp("popOver1").hide();
- };
- // 拍照
- Model.prototype.button9Click = function(event) {
- this.picSource(50, 1);
- };
- // 从相册选择
- Model.prototype.button10Click = function(event) {
- this.picSource(25, 2);
- };
- Model.prototype.picSource = function(quality, source) {
- var me = this;
- this.comp("popOver2").hide();
- function onSuccess(imageURI) {
- me.uploadImage(imageURI);
- }
- function onFail(message) {
- return message;
- }
- navigator.camera.getPicture(onSuccess, onFail, {
- quality : quality,
- sourceType : source
- });
- };
- Model.prototype.button1Click = function(fileName) {
- var src = "http://10.71.84.211:8080/baas/uploadImage?action=showImage&name=" + fileName;
- var imglist = $("<li> <a href="javascript:void(0)" data-bind="event:{click:$model._callModelFn.bind($model, 'a1Click\')}" class='button_a icon-android-close'></a><img class='imgStyle' src='"
- + src + "' data-bind="event:{click:$model._callModelFn.bind($model, 'image1Click\')}"></img></li>");
- justep.Bind.addNodes(this.getElementByXid("imglist"), imglist, this.getElementByXid("b_add"));
- };
- return Model;
- });
复制代码
PHP文件
- <?php
- class CeshiAction extends Action{
- public function test(){
- import('@.ORG.Util.UploadFile');
- $upload = new UploadFile(); //实例化上传类
- $upload->maxSize = 1024*1000*10; //设置附件上传大小
- $upload->allowExts = array(); //设置附件上传后缀
- //$upload->allowTypes = array('image/jpeg'); //设置上传文件类型
- $upload->savePath = "./Public/Uploads/"; //上传目录
- $upload->saveRule = $usersid."_".$orderid."_XJH_".date("YmdHis",time())."_".preciseTime('precise'); //上传名已时间戳保存
- if(!$upload->upload()) { //上传错误提示错误信息
- $this->error($upload->getErrorMsg());
- }
- else{ // 上传成功 获取上传文件信息
- $info = $upload->getUploadFileInfo();
- echo json_encode($info);
- }
- }
- }
- ?>
复制代码 |
|