Web-side file Upload, preview, download, delete

Source: Internet
Author: User
Tags filetime

 //html part <div class= "Item attachment attachmentnew" ><span class= "name" > Accessories </span><span class= "Triggerupload btnspan" onclick= "triggeruploadlist (This)" v-show= "operationtype<2" ><a> upload reimbursement voucher </a></span><form class= "Uploadform" style= "padding-left:150px" ><input type = "File" name= "file" class= "Filecontent hiddenclass" onchange= "douploadlist (This)"/><input type = "text" name= "SessionId" class= " Hiddenclass "/></form><div class=" PicC "><ul class=" filecontent "id=" FileBack2 "><li>< div class= "filename" > FileName </div><div class= "fileSize" > File size </div><div class= "Uploadingperson "> Uploader </div><div class=" fileTime "> Upload time </div><div class=" Fileremove "v-show=" Operationtype <2 "> Operation </div></li></ul></div></div>//Upload part//list display upload mode function douploadlist ( Thisobj) {var uploadformall=$ (thisobj). Parent ('. Uploadform '); var areacode=$.getcookie (' AreaCode '); var Sessionid=$.getcookie (' sessionId '); Uploadformall.children (' Input:eq (1) '). Val (sessionId); Uploadformall.children (' Input:eq (2) '). Val (AreaCode), var commonurl = $.getcookie (' Prefixurl '); var filename=$ (thisobj) [0].files[0];if (! FileName) {return false;} var thisp=$ (thisobj). Parent (' Form.uploadform '); Console.log (thisp[0]); var formData = new FormData (thisp[0]);// Console.log (file[0].size);//console.log (file[0].size/1024 + ' KB '); $.ajax ({url:commonurl+ '/file/upload ', type: ' POST ', data:formdata,async:false,cache:false,contenttype:false,processdata:false,success:function (data) {if ( Data.payload.results.file.fileName) {var file=data.payload.results.file;var imgurl=commonurl+ '/file/' +file.url; var Filename=file.filename;var filelastname = filename.substring (Filename.lastindexof (".") + 1, fileName.length); var Odate = new Date (file.createtime), createtime=odate.getfullyear () + '-' + (Odate.getmonth () + 1 > 9? odate.getmonth () + 1: ' 0 ' + (odate.getmonth () + 1)) + '-' + (Odate.getdate () > 9? oDate.getdate (): ' 0 ' + odate.getdate ());//var imgurlscan= ' http://view.officeapps.live.com/op/view.aspx?src= ' +imgurl var imgshow= ' <li picids= "' +file.id+ '" > ' + ' <div class= "fileName" ><a href= "' +imgurl+ '" target= "_blank" style= "COLOR: #78BC27" title= "' +filename+ '" > ' +filename+ ' </a></div> ' + ' <div class= ' fileSize ' style = "margin-left:4px" > ' +file.filesize+ ' </div> ' + ' <div class= "Uploadingperson" style= "margin-left:4px" > ' +file.username+ ' </div> ' + ' <div class= "FileTime" style= "margin-left:4px" > ' +createtime+ ' </div > ' + ' <div class= "Fileremove" style= "Margin-left:4px;color: #78BC27; cursor:pointer" onclick= "Removeimglist ( this,\ ' +file.id+ ' \ ') "><span class=" fa fa-trash-o "></span></div> ' + ' </li> '; Thisp.siblings ('. PicC '). Children ('. Filecontent '). Append (Imgshow);}},error:function (data) {Console.log (' server error! ‘);}});} function Removeimglist (OBJ,THISID) {$ (obj). Parent (' Li '). Remove (); var params = {Id:thisid};var URL = '/file/delete '; $.ajaxsend (URL, params). Done (function (data) {if (Data.code = = = ' 00000000 ') {}})}function Enlargelist ( obj) {var left = (document.documentelement.clientwidth-400)/2;var top = (document.documentelement.clientheight-400)/2 ; $ (obj). Parent (' div '). Siblings (' div '). "Show (). CSS (' left ', left+ ' px '). CSS (' top ', top+ ' px ');} function Enlargenoticelist (obj) {var thistop=document.getelementsbyclassname (' router '); var left = ( document.documentelement.clientwidth-400-220)/2;var top = (document.documentelement.clientheight-400)/2+thisTOP[0 ].scrolltop;$ (obj). Parent (' div '). Siblings (' div '). Show (). CSS (' left ', left+ ' px '). CSS (' top ', top+ ' px ');} function Closepiclist (obj) {$ (obj). hide ();} function Triggeruploadlist (obj) {$ (obj). Siblings (' Form.uploadform '). Children ('. Filecontent '). Trigger (' click ');} Backfill Section Filebackfill (Arrdata,strdom,type) {///Background data arrdata,strdom Click Upload Attachments Dom object, type data operation types (create, edit, approve, view) var Commonurl = $ . GetCookie (' Prefixurl '); var thisp=$ (' #${strdom} '); Arrdata.foreach (File=>{var Filename=file.filenAme;var imgurl=commonurl+ '/file/' +file.url;var filelastname = file.suffixName.substr (1);//console.log (file[0].size /1024 + ' KB '), var odate = new Date (file.createtime), Var createtime=odate.getfullyear () + '-' + (Odate.getmonth () + 1 > 9? Odate.getmonth () + 1: ' 0 ' + (odate.getmonth () + 1)) + '-' + (Odate.getdate () > 9? odate.getdate (): ' 0 ' + ODATE.GETDA Te ()); if (type=== ' 2 ' | | type=== ' 3 ') {var fileitem= ' <li picids= "' +file.id+ '" > ' + ' <div class= "fileName" ><a href= "' +imgurl+ '" target= "_blank" style= "color: #78BC27" title= "' +filename+ '" > ' +filename+ ' </a></div> ' + ' <div class= "FileSize" style= "margin-left:4px" > ' +file.filesize+ ' </div> ' + ' <div class= "Uploadingperson" style= " margin-left:4px "> ' +file.username+ ' </div> ' + ' <div class=" FileTime "style=" margin-left:4px "> ' + Createtime+ ' </div> ' + ' </li> ';} Else{var fileitem= ' <li picids= "' +file.id+ '" > ' + ' <div class= "fileName" ><a href= "' +imgurl+ '" target= "_ Blank "style=" color: #78bc27 "title=" ' +filename+ ' > ' +filename+ ' </a></div> ' + ' <div class= ' fileSize ' style= ' margin-left : 4px "> ' +file.filesize+ ' </div> ' + ' <div class=" Uploadingperson "style=" margin-left:4px "> ' + File.username+ ' </div> ' + ' <div class= "FileTime" style= "margin-left:4px" > ' +createtime+ ' </div> ' + ' <div class= "Fileremove" style= "Margin-left:4px;color: #78BC27; cursor:pointer" onclick= "Removeimglist (this,\" + File.id+ ' \ ') "><span class=" fa fa-trash-o "></span></div> ' + ' </li> ';} Thisp.append (Fileitem);}),

Web-side file Upload, preview, download, delete

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.