• AppCan的图片、文件操作、上传、下载操作 From Ken


    <!DOCTYPE html>
    <html class="ui-mobile landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
      <head>
        <title>
        </title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" href="css/ui-media.css">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-apple.css">
        <script src="js/zy_anim.js">
        </script>
        <script src="js/zy_control.js">
        </script>
     	<script src="js/zy_tmpl.js">
        </script>
      </head>
      <body class="ui-mobile-viewport" >
       
    <div id="page" class="ui-page ui-body-d ui-page-active ui-header-fixed" tabindex="0">
    
    <div data-role="header" class="ui-header ui-bar-iphone " >
    <h1 class="ui-title" tabindex="0" role="heading" aria-level="1">Images</h1> 
    <div class="ui-btn  ui-btn-right ui-btn-corner-all ui-shadow  ui-btn-a  " onclick="actionsheet();">  <span class="ui-btn-inner ui-btn-corner-all"> <span class="ui-btn-text">选择</span>  </span></div> 
    
    </div>
    
    <div id="msgid" class="ui-bar ui-bar-e ">
    </div>
    
    <div class="ui-content ui-body-d">
    <img id="imgid" src="img/2.png" style="height:500px;450px;position:absolute;left:0.5em;"/> 
    </div>
    
    <div data-role="footer" class="ui-footer ui-bar-a ui-footer-fixed">
    <div class="ui-bar ui-bar-a ">
    <div class="ui-btn   ui-btn-corner-all ui-shadow  ui-btn-a ui-btn-inline " onclick="viewpic();">  <span class="ui-btn-inner ui-btn-corner-all"> <span class="ui-btn-text">图片查看器</span>  </span> <button class="ui-btn-hidden">按钮</button> </div> 
    <div class="ui-btn   ui-btn-corner-all ui-shadow  ui-btn-a ui-btn-inline " onclick="downloadurl();">  <span class="ui-btn-inner ui-btn-corner-all"> <span class="ui-btn-text">下载网络图片</span>  </span> <button class="ui-btn-hidden">按钮</button> </div> 
    <div class="ui-btn   ui-btn-corner-all ui-shadow  ui-btn-a ui-btn-inline " onclick="uploadpic();">  <span class="ui-btn-inner ui-btn-corner-all"> <span class="ui-btn-text">上传</span>  </span> <button class="ui-btn-hidden">按钮</button> </div> 
    
    </div>
    
    
    </div>
    
    </div>
    <script>
    var imgurl = "wgt://img/2.png";//默认图片url
    
    //显示log
    function setLog(msg){
    	document.getElementById("msgid").innerHTML = msg;
    }
    
    //弹出actionSheet
    function actionsheet(){
    	uexWindow.actionSheet("选择图片", "取消", ["照相机拍摄","本地文件","网络文件"]);
    }
    //通过图片查看器查看图片
    function viewpic(){
    	var ar = new Array();
    	ar[0]=imgurl;
    	uexImageBrowser.open(ar);
    }
    
    //下载网络图片
    var dopCode=1;
    var inSavePath=null;
    function downloadurl(){
    	if(imgurl.indexOf("http://")==0){
    		var q = imgurl.match(/.*\.(.*)/);
    		inSavePath = (new Date()).getTime()+"."+q[1];
    		uexDownloaderMgr.createDownloader(dopCode); 
    	}else{
    		uexWindow.toast(0,5,"非网络图片",1000);
    	}
    }
    //上传图片
    var uploadHttp = "http://*.*.net/server/upload.php";
    /*upload.php 和普通的上传一样, 你写个upload.php,文件里面就一个<?php file_put_contents('log',print_r($_FILES,1));就知道了,不要来加群,就为了问这个,谢谢*/
    var uopCode =2;
    function uploadpic(){
    	if(imgurl.indexOf("http://")<0)
    		uexUploaderMgr.createUploader(uopCode,uploadHttp);
    	else
    		uexWindow.toast(0,5,"非本地图片",1000);
    }
    
    window.uexOnload = function(){
    
    	uexWindow.cbActionSheet = function(opId,dataType,data){
    		switch(parseInt(data)){
    		case 0:
    			uexCamera.open();
    			break;
    		case 1:
    			uexFileMgr.explorer("");
    			break;
    		case 2:
    			uexWindow.prompt("提示", "输入网络图片URL", "",["确定","取消"]);
    			break;
    		}
    	}
    	uexWindow.cbPrompt=function(opId,dataType,data){
    		if(dataType==1){
    			var d = eval("("+data+")");
    			if(d.num=="0"){
    				if(d.value.indexOf('http://')>-1){
    					imgurl=d.value;
    					document.getElementById("imgid").src=imgurl;
    				}
    				else
    					alert("网络URL错误");
    			}
    			
    		}
    	}
    	uexCamera.cbOpen = function(opId,dataType,data){
    		if(dataType==0)
    		{
    			imgurl = data;
    			document.getElementById("imgid").src=imgurl;
    		}
    	}
    	uexFileMgr.cbExplorer = function(opId,dataType,data){
    		uexLog.sendLog(dataType); 
    		if(dataType==0){
    			uexLog.sendLog(data);
    			imgurl = data;
    			document.getElementById("imgid").src=imgurl;
    			uexLog.sendLog(document.getElementById("imgid").src);
    		}
    	}
    	//****************下载回调***************
    	uexDownloaderMgr.cbCreateDownloader=function(opId,dataType,data){
    		uexDownloaderMgr.download(dopCode,imgurl,inSavePath,0);
    		setLog("开始下载图片");
    	}
    	uexDownloaderMgr.onStatus = function(opId,fileSize,percent,status){
    		if(status == 0)
    			setLog("下载进度:"+percent+"%");
    		if(status == 1){
    			setLog("下载完成");
    			imgurl = inSavePath;
    			uexDownloaderMgr.closeDownloader(dopCode);
    		}
    		if(status == 2){
    			setLog("下载出错");
    			uexDownloaderMgr.closeDownloader(dopCode); 
    			uexFileMgr.deleteFileByPath(inSavePath);
    		}
    	}
    	//******************************************
    	//****************上传回调***************
    	uexUploaderMgr.cbCreateUploader = function(opId,dataType,data){
    		uexUploaderMgr.uploadFile(uopCode,imgurl,"filename",1);
    		setLog("开始上传图片");
    	}
    	uexUploaderMgr.onStatus = function(opId,fileSize,percent,serverPath,status){
    		if(status==0)
    			setLog("上传进度:"+percent+"%");
    		if(status == 1){
    			setLog("上传完成");
    			uexUploaderMgr.closeUploader(uopCode);
    		}
    		if(status == 2){
    			setLog("上传出错");
    		}
    	}
    	//******************************************
    }
    </script>
      </body>
    </html>
    

    我的QQ群:

    PHPer&Webgame&移动开发,群号:95303036


     

  • 相关阅读:
    js 获取浏览器版本号
    怎样写具体设计文档
    android PreferenceScreen使用笔记
    支持向量机通俗导论(理解SVM的三层境地)
    算法导论 第6章 堆排序(简单选择排序、堆排序)
    人脸识别算法初次了解
    循环队列
    ubuntu 下操作文件夹,出现Permission denied的解决的方法
    JFreeChart的使用
    隐藏Activity标题栏
  • 原文地址:https://www.cnblogs.com/lein317/p/5067617.html
Copyright © 2020-2023  润新知