search
HomeWeb Front-endH5 TutorialHTML5 Plus realizes the function of taking photos or uploading pictures from photo albums on mobile APP

This article mainly introduces the Camera, GalleryIO, Storage and Uploader of HTML5 Plus in detail, and the relevant information to realize the function of taking pictures or selecting pictures in the album to upload on the mobile APP. Interested friends can refer to it

Use the Camera, GalleryIO, Storage and Uploader of HTML Plus to take pictures with the mobile APP or select pictures from the album to upload. The Camera module manages the camera of the device and can be used for photo and video operations. The camera management object is obtained through plus.camera. The Gallery module manages system albums and supports functions such as selecting pictures or video files from the album and saving pictures or video files to the album. Get the album management object through plus.gallery. The IO module manages the local file system and is used for operations such as directory browsing, file reading, and file writing of the file system. File system management objects can be obtained through plus.io. The Storage module manages the application's local data storage area and is used to save and read application data. The difference between application local data and localStorage and sessionStorage is that the data valid domain is different. The former can operate across domains within the application, the data storage period is persistent, and there is no capacity limit. Application local data management objects can be obtained through plus.storage. The Uploader module manages network upload tasks, is used to upload various files locally to the server, and supports cross-domain access operations. The upload management object can be obtained through plus.uploader. Uploader uploads data using HTTP POST method, and the data format conforms to the Multipart/form-data specification, that is, rfc1867 (Form-based File Upload in HTML) protocol.

<!doctype html>  
<html class="feedback">  
 <head>  
  <meta charset="utf-8" />  
  <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />  
  <meta name="misapplication-tap-highlight" content="no" />  
  <meta name="HandheldFriendly" content="true" />  
  <meta name="MobileOptimized" content="320" />  
  <title>HTML5 Plus 拍照或者相册选择图片上传</title>  
  <link rel="stylesheet" href="../../css/mui.min.css">  
  <link rel="stylesheet" type="text/css" href="../../css/app.css" />  
  <link rel="stylesheet" type="text/css" href="../../css/iconfont.css" />  
  <link rel="stylesheet" type="text/css" href="../../css/feedback-page.css" />  
  <link rel="stylesheet" href="../../css/font-awesome.min.css">  
  <script src="../../js/jquery.js"></script>  
  <script type="text/javascript" src="../../js/common.js"></script>  
  <script type="text/javascript" src="../../js/utitls.js"></script>  
  <script type="text/javascript" src="http://api.map.baidu.com/api?ak=59PBaEOro16CiH2W4CG81zEN&v=2.0"></script>  
  <style type="text/css">  
   .del {   
    position: absolute;   
    top:1px;   
    right: 1px;    
    display: block;         
       line-height: 1;   
       cursor: pointer;   
       color:#fff;   
    }   
  
   .del:hover {   
    color:#ff3333;   
   }   
  </style>  
  <style>  
   .table-view {   
    position: relative;   
    margin-top: 0;   
    margin-bottom: 0;   
    padding-left: 0;   
    list-style: none;   
    background-color: #f5f5f5;   
   }   
      
   .table-view-cell {   
    position: relative;   
    overflow: hidden;   
    padding: 0px 15px;   
    -webkit-touch-callout: none;   
    margin-bottom: 1px;   
   }   
      
   .table-view-cell:after {   
    position: absolute;   
    right: 0;   
    bottom: 0;   
    left: 0px;   
    height: 1px;   
    content: &#39;&#39;;   
    -webkit-transform: scaleY(.5);   
    transform: scaleY(.5);   
    background-color: #c8c7cc;   
   }   
      
   .table-view-cell>a:not(.btn) {   
    position: relative;   
    display: block;   
    overflow: hidden;   
    margin: -0px -15px;   
    padding: inherit;   
    white-space: nowrap;   
    text-overflow: ellipsis;   
    color: inherit;   
    background-color: #75b9f4;   
    height: 40px;   
    line-height: 40px;   
   }   
      
   .navigate-right:after   
   {   
    font-family: Muiicons;   
    font-size: inherit;   
    line-height: 1;   
    position: absolute;   
    top: 50%;   
    display: inline-block;   
    -webkit-transform: translateY(-50%);   
    transform: translateY(-50%);   
    text-decoration: none;   
    color: #666;   
    -webkit-font-smoothing: antialiased;   
   }   
      
   .table-view-cell.collapse .collapse-content {   
    position: relative;   
    display: none;   
    overflow: hidden;   
    margin: 0px -15px 0px;   
    padding: 0px 0px !important;   
    -webkit-transition: height .35s ease;   
    -o-transition: height .35s ease;   
    transition: height .35s ease;   
    background-color: transparent;   
   }   
   .image-item{   
    position: relative;   
   }   
   .image-item .info{   
    position: absolute;   
    top:0px;   
    left:4px;   
    color: #ff9900;   
    font-size: 12px;         
       
   }   
  </style>  
 </head>  
 <body>  
  <header class="bar bar-nav">  
   <h1 id="拍照或者相册选择图片上传">拍照或者相册选择图片上传</h1>  
  </header>  
  <p class="content">  
   <p style="margin-top: 10px;"></p>  
   <input type="hidden" id="ckjl.id" name="ckjl.id" value="429">  
     <p class="collapse-content" >  
      <form>  
       <label class="row-label"></label>  
       <p id=&#39;F_CKJLBS&#39; class="row image-list">  
        <p class="image-item " id="F_CKJLB" onclick="showActionSheet(this);"></p>  
      </p>  
      </form>  
     </p>  
  </p>  
  <script src="../../js/mui.min.js"></script>  
<script>  
 var procinstid = 0;   
 //初始化页面执行操作   
 function plusReady() {   
  //Android返回键监听事件   
  plus.key.addEventListener(&#39;backbutton&#39;,function(){   
   myclose();   
  },false);   
 }   
 if (window.plus) {   
  plusReady();   
 } else {   
  document.addEventListener(&#39;plusready&#39;, plusReady, false);   
 }   
  //加载页面初始化需要加载的图片信息   
  //或者相册IMG_20160704_112620.jpg   
  //imgId:图片名称:1467602809090或者IMG_20160704_112620   
  //imgkey:字段例如:F_ZDDZZ   
  //ID:站点编号ID,例如429   
  //src:src="file:///storage/emulated/0/Android/data/io.dcloud.HBuilder/.HBuilder/apps/HBuilder/doc/upload/F_ZDDZZ-1467602809090.jpg"  
  function showImgDetail (imgId,imgkey,id,src) {     
   var html = "";   
   html +=&#39;<p  id="Img&#39;+imgId+imgkey+&#39;" class="image-item ">&#39;;    
   html +=&#39; <img  src="/static/imghwm/default1.png"  data-src="" data-preview-group="  class="lazy"  id="picBig" data-preview- data-preview-group="1" &#39;+src+&#39;/ alt="HTML5 Plus realizes the function of taking photos or uploading pictures from photo albums on mobile APP" >&#39;;   
   html +=&#39; <span class="del" onclick="delImg(\&#39;&#39;+imgId+&#39;\&#39;,\&#39;&#39;+imgkey+&#39;\&#39;,&#39;+id+&#39;);">&#39;;       
   html +=&#39;  <p class="fa fa-times-circle"></p>&#39;;    
   html +=&#39; </span>&#39;;    
   html +=&#39;</p>&#39;;   
   $("#"+imgkey+"S").append(html);   
  }   
  //删除图片   
  //imgId:图片名称:IMG_20160704_112614   
  //imgkey:字段,例如F_ZDDZZ   
  //ID:站点编号ID,例如429   
  function delImg(imgId,imgkey,id){   
   var bts = ["是", "否"];   
   plus.nativeUI.confirm("是否删除图片?", function(e) {   
     var i = e.index;   
     if (i == 0) {   
      var itemname=id+"img-"+imgkey;//429img-F_ZDDZZ   
      var itemvalue=plus.storage.getItem(itemname);   
      //{IMG_20160704_112614,_doc/upload/F_ZDDZZ-IMG_20160704_112614.jpg,file:///storage/emulated/0/Android/data/io.dcloud...../doc/upload/F_ZDDZZ-1467602809090.jpg}   
      if(itemvalue!=null){   
       var index=itemvalue.indexOf(imgId+",");   
       if(index==-1){//没有找到   
        delImgfromint(imgId,imgkey,id,index);   
       }else{    
        delImgFromLocal(itemname,itemvalue,imgId,imgkey,index); //修改,加了一个index参数   
       }   
          
      }else{   
       delImgfromint(imgId,imgkey,id);    
      }   
     }   
    },"查勘", bts);   
   /*var isdel = confirm("是否删除图片?");   
   if(isdel == false){   
    return;   
   }*/   
      
      
  }   
  function delImgFromLocal(itemname,itemvalue,imgId,imgkey,index){   
     var wa = plus.nativeUI.showWaiting();   
     var left=itemvalue.substr(0,index-1);   
     var right=itemvalue.substring(index,itemvalue.length);   
     var end=right.indexOf("}");   
     rightright=right.substring(end+1,right.length);   
     var newitem=left+right;   
     plus.storage.setItem(itemname,newitem);    
     myAlert("删除成功");   
     $("#Img"+imgId+imgkey).remove();   
     wa.close();   
  }   
  //选取图片的来源,拍照和相册   
  function showActionSheet(conf){   
     var pid = conf.id;   
           var actionbuttons=[{title:"拍照"},{title:"相册选取"}];   
           var actionstyle={title:"选择照片",cancel:"取消",buttons:actionbuttons};   
           plus.nativeUI.actionSheet(actionstyle, function(e){   
              if(e.index==1){   
               getImage(pid);   
              }else if(e.index==2){   
               galleryImg(pid);   
              }   
           } );   
        }   
  //相册选取图片   
        function galleryImg(pid) {   
            plus.gallery.pick( function(p){   
             //alert(p);//file:///storage/emulated/0/DCIM/Camera/IMG_20160704_112620.jpg   
             plus.io.resolveLocalFileSystemURL(p, function(entry) {   
              //alert(entry.toLocalURL());//file:///storage/emulated/0/DCIM/Camera/IMG_20160704_112620.jpg   
     //alert(entry.name);//IMG_20160704_112620.jpg   
     compressImage(entry.toLocalURL(),entry.name,pid);   
    }, function(e) {   
     plus.nativeUI.toast("读取拍照文件错误:" + e.message);   
    });   
            }, function ( e ) {   
            }, {   
             filename: "_doc/camera/",   
             filter:"image"   
            } );   
        }   
  // 拍照   
  function getImage(pid) {   
   var cmr = plus.camera.getCamera();   
   cmr.captureImage(function(p) {   
    //alert(p);//_doc/camera/1467602809090.jpg   
    plus.io.resolveLocalFileSystemURL(p, function(entry) {   
     //alert(entry.toLocalURL());//file:///storage/emulated/0/Android/data/io.dcloud...../doc/camera/1467602809090.jpg   
     //alert(entry.name);//1467602809090.jpg   
     compressImage(entry.toLocalURL(),entry.name,pid);   
    }, function(e) {   
     plus.nativeUI.toast("读取拍照文件错误:" + e.message);   
    });   
   }, function(e) {   
   }, {   
    filename: "_doc/camera/",   
    index: 1   
   });   
  }   
  //压缩图片   
  function compressImage(url,filename,pid){   
   var name="_doc/upload/"+pid+"-"+filename;//_doc/upload/F_ZDDZZ-1467602809090.jpg   
   plus.zip.compressImage({   
     src:url,//src: (String 类型 )压缩转换原始图片的路径   
     dst:name,//压缩转换目标图片的路径   
     quality:20,//quality: (Number 类型 )压缩图片的质量.取值范围为1-100   
     overwrite:true//overwrite: (Boolean 类型 )覆盖生成新文件   
    },   
    function(event) {    
     //uploadf(event.target,pid);   
     var path = name;//压缩转换目标图片的路径   
     //event.target获取压缩转换后的图片url路   
     //filename图片名称   
     saveimage(event.target,pid,filename,path);   
    },function(error) {   
     plus.nativeUI.toast("压缩图片失败,请稍候再试");   
   });   
  }   
  //保存信息到本地   
  /**   
   *    
   * @param {Object} url  图片的地址   
   * @param {Object} pid  字段的名称   
   * @param {Object} name   图片的名称   
   */   
  function saveimage(url,pid,name,path){   
   //alert(url);//file:///storage/emulated/0/Android/data/io.dcloud...../doc/upload/F_ZDDZZ-1467602809090.jpg   
   //alert(path);//_doc/upload/F_ZDDZZ-1467602809090.jpg   
   var  state=0;   
   var wt = plus.nativeUI.showWaiting();   
    //  plus.storage.clear();    
   namename=name.substring(0,name.indexOf("."));//图片名称:1467602809090   
   var id = document.getElementById("ckjl.id").value;   
   var itemname=id+"img-"+pid;//429img-F_ZDDZ   
   var itemvalue=plus.storage.getItem(itemname);   
   if(itemvalue==null){   
    itemvalue="{"+name+","+path+","+url+"}";//{IMG_20160704_112614,_doc/upload/F_ZDDZZ-IMG_20160704_112614.jpg,file:///storage/emulated/0/Android/data/io.dcloud...../doc/upload/F_ZDDZZ-1467602809090.jpg}   
   }else{     
    itemvalueitemvalue=itemvalue+"{"+name+","+path+","+url+"}";   
   }   
   plus.storage.setItem(itemname, itemvalue);   
      
   var src = &#39;src="&#39;+url+&#39;"&#39;;   
   //alert("itemvalue="+itemvalue);   
   showImgDetail(name,pid,id,src);   
   wt.close();   
      
  }   
  //上传图片,实例中没有添加上传按钮   
  function uploadimge(agree,back) {   
  //plus.storage.clear();   
   var wa = plus.nativeUI.showWaiting();   
   var DkeyNames=[];   
   var id = document.getElementById("ckjl.id").value;    
   var length=id.toString().length;    
   var ididnmae=id.toString();   
   var numKeys=plus.storage.getLength();   
   var task = plus.uploader.createUpload(getUrl() + &#39;url&#39;, {   
        method: "POST"   
       },   
       function(t, status) {   
        if (status == 200) {   
         console.log("上传成功");   
          $.ajax({   
          type: "post",   
          url: getUrl() + &#39;url&#39;,   
          data: {   
           taskId: taskId,   
           voteAgree: agree,   
           back: back,   
           voteContent: $("#assign").val(),   
          },   
          async: true,   
          dataType: "text",   
          success: function(data) {   
           wa.close();   
           goList(data);   
             
              
          },   
          error: function() {   
           wa.close();   
           myAlert("网络错误,提交审批失败,请稍候再试");   
          }   
         });   
             
            
        } else {   
         wa.close();   
         console.log("上传失败");    
        }   
       }   
      );   
   task.addData("id",id);   
   for(var i=0; i<img src="/static/imghwm/default1.png"  data-src="https://img.php.cn/upload/article/000/000/009/841045a178535501ccc9d1ecc14e9ff2-0.png?x-oss-process=image/resize,p_40"  class="lazy" Array.length;i++){     
    var itemkey=id+"img-"+imgArray[i];   
     if(plus.storage.getItem(itemkey)!=null){   
     var itemvalue=plus.storage.getItem(itemkey).split("{");   
     for(var img=1;img<itemvalue.length;img++){   
      var imgname=itemvalue[img].substr(0,itemvalue[img].indexOf(","));   
      var imgurl=itemvalue[img].substring(itemvalue[img].indexOf(",")+1,itemvalue[img].lastIndexOf(","));   
      task.addFile(imgurl,{key:imgurl});   
     }   
    }   
   }   
   task.start();   
      
  }   
</script>  
</body>  
</html>

Rendering:

##The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Implementation of Html5 clipboard function

Using PHP and HTML5 FormData to achieve refresh-free file upload

Html5 mobile terminal award-winning seamless scrolling animation implementation

The above is the detailed content of HTML5 Plus realizes the function of taking photos or uploading pictures from photo albums on mobile APP. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
H5 Code Examples: Practical Applications and TutorialsH5 Code Examples: Practical Applications and TutorialsApr 25, 2025 am 12:10 AM

H5 provides a variety of new features and functions, greatly enhancing the capabilities of front-end development. 1. Multimedia support: embed media through and elements, no plug-ins are required. 2. Canvas: Use elements to dynamically render 2D graphics and animations. 3. Local storage: implement persistent data storage through localStorage and sessionStorage to improve user experience.

The Connection Between H5 and HTML5: Similarities and DifferencesThe Connection Between H5 and HTML5: Similarities and DifferencesApr 24, 2025 am 12:01 AM

H5 and HTML5 are different concepts: HTML5 is a version of HTML, containing new elements and APIs; H5 is a mobile application development framework based on HTML5. HTML5 parses and renders code through the browser, while H5 applications need to run containers and interact with native code through JavaScript.

The Building Blocks of H5 Code: Key Elements and Their PurposeThe Building Blocks of H5 Code: Key Elements and Their PurposeApr 23, 2025 am 12:09 AM

Key elements of HTML5 include,,,,,, etc., which are used to build modern web pages. 1. Define the head content, 2. Used to navigate the link, 3. Represent the content of independent articles, 4. Organize the page content, 5. Display the sidebar content, 6. Define the footer, these elements enhance the structure and functionality of the web page.

HTML5 and H5: Understanding the Common UsageHTML5 and H5: Understanding the Common UsageApr 22, 2025 am 12:01 AM

There is no difference between HTML5 and H5, which is the abbreviation of HTML5. 1.HTML5 is the fifth version of HTML, which enhances the multimedia and interactive functions of web pages. 2.H5 is often used to refer to HTML5-based mobile web pages or applications, and is suitable for various mobile devices.

HTML5: The Building Blocks of the Modern Web (H5)HTML5: The Building Blocks of the Modern Web (H5)Apr 21, 2025 am 12:05 AM

HTML5 is the latest version of the Hypertext Markup Language, standardized by W3C. HTML5 introduces new semantic tags, multimedia support and form enhancements, improving web structure, user experience and SEO effects. HTML5 introduces new semantic tags, such as, ,, etc., to make the web page structure clearer and the SEO effect better. HTML5 supports multimedia elements and no third-party plug-ins are required, improving user experience and loading speed. HTML5 enhances form functions and introduces new input types such as, etc., which improves user experience and form verification efficiency.

H5 Code: Writing Clean and Efficient HTML5H5 Code: Writing Clean and Efficient HTML5Apr 20, 2025 am 12:06 AM

How to write clean and efficient HTML5 code? The answer is to avoid common mistakes by semanticizing tags, structured code, performance optimization and avoiding common mistakes. 1. Use semantic tags such as, etc. to improve code readability and SEO effect. 2. Keep the code structured and readable, using appropriate indentation and comments. 3. Optimize performance by reducing unnecessary tags, using CDN and compressing code. 4. Avoid common mistakes, such as the tag not closed, and ensure the validity of the code.

H5: How It Enhances User Experience on the WebH5: How It Enhances User Experience on the WebApr 19, 2025 am 12:08 AM

H5 improves web user experience with multimedia support, offline storage and performance optimization. 1) Multimedia support: H5 and elements simplify development and improve user experience. 2) Offline storage: WebStorage and IndexedDB allow offline use to improve the experience. 3) Performance optimization: WebWorkers and elements optimize performance to reduce bandwidth consumption.

Deconstructing H5 Code: Tags, Elements, and AttributesDeconstructing H5 Code: Tags, Elements, and AttributesApr 18, 2025 am 12:06 AM

HTML5 code consists of tags, elements and attributes: 1. The tag defines the content type and is surrounded by angle brackets, such as. 2. Elements are composed of start tags, contents and end tags, such as contents. 3. Attributes define key-value pairs in the start tag, enhance functions, such as. These are the basic units for building web structure.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.