日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

uploadify文件上传以及预览

發布時間:2023/12/2 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 uploadify文件上传以及预览 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

項目中利用poi實現預覽基本步驟:(其他的導入jar包什么的在別人資料上可以找到,我實現這個功能也是借鑒+實踐才成功的~我提供的只是我接觸項目的思路和代碼。見諒!【滑稽】)

先pdf,然后swf

安裝OpenOffice后啟動cmd:C:/Program Files (x86)/OpenOffice 4/program/soffice.exe -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\"

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?安裝路徑:C:/Program Files (x86)/OpenOffice 4/program/soffice.exe ;

1.(jsp頁面中)項目中uploadify上傳js格式

使用uploadify需要導入uploadify.css、jquery.uploadify.min.js等jar包,在官方domes有,嗯,有,還有各種屬性;

$('#file_upload').uploadify({'swf' : '${ctx}/js/uploadify3.2.1/uploadify.swf','uploader':'${ctx}/upload/uploadAction!uploadFile?jsessionid='+"<%=request.getParameter("fkId")%>",'buttonText' : '添加,'buttonClass' : 'uploadify','fileObjName' : 'uploadify','formData' : {'fkId' : '${fkId}'},'onUploadSuccess' : function(file, data, response) {}});});
2.js中調用預覽的方法(只是提供一個js方法,放在jsp那里自己看咯)

function preview(id) {var param = '';if(typeof id!='undefined')param = '&id='+id;var url='${ctx}/jsp/file/documentView.jsp?fkId='+fkId+param;window.top.art.dialog.open(url,{title:"在線預覽",width:'80%',height:'90%',lock:true,opacity:0.3,button: [ { name: '關閉', callback: function () {return true; }, focus: true }]});}


3.documentView.jsp頁面(項目數據)上面js方法中在線預覽內填充的頁面

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <%@ include file="/common/taglibs.jsp"%> <%@ include file="/common/jqueryhead.jsp" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html style="height: 100%;width: 100%;"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> html, body { height:100%; }body { margin:0; padding:0; overflow:hidden; } /* #flashContent{display: none;} */#imgFile{width: 100%;height: 100%;display: none;}.module{display: none;}</style> <script type="text/javascript" src="${ctx}/jsp/file/js/swfobject/swfobject.js"></script><script type="text/javascript" src="${ctx}/jsp/file/js/flexpaper_flash.js"></script><script type="text/javascript">var imgSuffix="bmp,jpeg,gif,psd,png,tiff,tga,eps,jpg"; //常用圖片文件格式var mp4Suffix="mp4,avi,flv,rmvb,3gp"; //常用視頻格式var officeSuffix="txt,doc,xls,ppt,pdf,dwg,exb,docx,xlsx,pptx,wps,et,dps,html,xml,swf";$(function(){var fkId="${param.fkId}";var ids="${param.id}";console.log("documentView.jsp:"+fkId+"-----");//var ids="${param.id}";//讀取文件格式$.ajax({url:'${ctx}/upload/uploadAction!getFileStaff?ids='+ids,type:'post',data: "idd="+fkId ,async:false,success:function(data){console.log(data);data=eval('('+data+')');if(data.isExists=="false"){loadNoP(1); //文件不存在}else{var id=data.id;var pt=data.realName;var staff=data.extension;//文件格式console.log(id+"--"+staff+"==="+officeSuffix.indexOf(staff)+"----"+imgSuffix.indexOf(staff));if(imgSuffix.indexOf(staff)!=-1){ //是否是圖loadImage(pt);}else if(officeSuffix.indexOf(staff)!=-1){ //可預覽loadDocument(pt);}else{loadNoP(0);}}}});});/***預覽圖片 不需要轉換*/function loadImage(pt){$(".module").hide();console.log(pt+"");/* $("#imgFile").find("img").attr("src","${ctx}/downQybzh/downQybzhAction!preview?fkId=${param.id}"); */$("#imgFile").find("img").attr("src",pt);$("#imgFile").show();}/**不能預覽**/function loadNoP(status){$(".module").hide();if(status==1){$("#imgFile").find("img").attr("src","${ctx}/jsp/file/notExistsFile.jpg").attr("width","100%").attr("height","100%");}else{$("#imgFile").find("img").attr("src","${ctx}/jsp/file/descpreview.jpg").attr("width","100%").attr("height","100%");}$("#imgFile").show();}/***需要轉換*/<%-- function loadDocument(){$("#emb").attr("src","<%=session.getAttribute("swfpath")%>");$(".module").hide();$("#flashContent").show();} --%>function loadDocument(pt){console.log("loadDocument:"+pt);var fkId="${param.fkId}";var swfVersionStr = "9.0"; //版本var xiSwfUrlStr = "${ctx}/jsp/file/js/swfobject/expressInstall.swf";//播放器var flashvars={};flashvars = { //swf相對路徑 //SwfFile 后跟項目下的圖片路徑",SwfFile : decodeURI(pt),//SwfFile:escape('/pipe/upload/626ea0ed1e844eb5973005474701acdd測厚管線清單與記錄201704.swf'),Scale : 0.8, //Scale是0-1之間的數,表示顯示的放大參數 ZoomTransition : "easeOut", ZoomTime : 0.5, ZoomInterval : 0.1,FitPageOnLoad : false,FitWidthOnLoad : true,FitHeightOnload : true,PrintEnabled : false,FullScreenAsMaxWindow : false,ProgressiveLoading : true,// PrintToolsVisible : false,ViewModeToolsVisible : true,ZoomToolsVisible : true,FullScreenVisible : true,NavToolsVisible : true,CursorToolsVisible : true,SearchToolsVisible : true,WMode:"transparent",localeChain: "en_US",};var params = {};params.quality = "high";params.bgcolor = "#999999";params.allowscriptaccess = "sameDomain";params.allowfullscreen = "true";var attributes = {};attributes.id = "FlexPaperViewer";attributes.name = "FlexPaperViewer";swfobject.embedSWF("FlexPaperViewer.swf", "flashContent", "100%", "100%",swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);swfobject.createCSS("#flashContent", "display:block;text-align:left;");$(".module").hide();$("#flashContent").show();};</script> </head> <body style="height: 100%;width: 100%;"><center><div style="height: 100%;width: 100%"><!-- 需要轉換的 --><div id="flashContent" class="module" style="height: 100%;width: 100%;" > 這里是預覽<!-- <EMBED id="emb" src="" style="height: 100%;width: 100%" type=application/x-shockwave-flash wmode="transparent "quality="high "></EMBED> --></div><!-- 圖片預覽 --><div id="imgFile" class="module" style="height: 100%;width: 100%"><img src="" width="100%" height="100%"/></div> <!-- 視頻預覽 --><div id="mp4Play" class="module" style="height: 100%;width: 100%" ><iframe width="100%" height="100%" frameborder="0" scrolling="no"></iframe></div></div></center></body> </html>


4.后臺判斷后綴方法

后面的兩行代碼:

? String json = new JsonMapper().toJson(ufi);
??Struts2Utils.renderText(json);

只是轉json數據格式;

public void getFileStaff() {fkId=request.getParameter("idd");Map<String, String> map = new HashMap<String, String>();map.put("fkId", fkId);List<UploadFileInfo> ufis = uploadFileInfoService.query(map);UploadFileInfo ufi = null;ufi = uploadFileInfoService.getById(request.getParameter("ids"));if (ufi != null) {String paths=null;try {paths=Encoding.encode(ufi.getName(), "UTF-8");} catch (UnsupportedEncodingException e) {e.printStackTrace();}ufi.setIsExists("true");File file = new File(ufi.getDirectory() +request.getParameter("idd")+ paths);if (!file.exists()) {ufi.setIsExists("false");// 文件不存在uploadFileInfoService.delete(ufi.getId());}String converfilename = (ufi.getDirectory() +request.getParameter("idd")+ paths).replaceAll("\\\\", "/");String[] str={"bmp","jpeg","gif","psd","png","tiff","tga","eps","jpg"};String ext=ufi.getExtension();//判斷是否包含extboolean isContains = Arrays.asList(str).contains(ext);if(isContains){String realname=(request.getParameter("idd")+ paths).replaceAll("\\\\", "/");ufi.setRealName("/pipe/upload/"+realname);}else{DocConvert d=new DocConvert(converfilename);System.out.println("lujingming:"+d);d.conver();d.getswfPath();String swfpath = "/pipe/upload"+d.getswfPath().substring(d.getswfPath().lastIndexOf("/")); System.out.println("打印后的路徑:"+d.getswfPath());System.out.println("項目里的路徑:"+swfpath);ufi.setRealName(swfpath);}} else {ufi = new UploadFileInfo();ufi.setIsExists("false");// 文件不存在}String json = new JsonMapper().toJson(ufi);Struts2Utils.renderText(json);}

5.工具類DocConvert

在上面判斷的方法中調用此類,用來啟動OpenOffice應用,進而轉換格式;

import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import java.util.Properties;import com.artofsolving.jodconverter.DocumentConverter; import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter; import com.pacia.jfds.create.tools.Property;/** * doc docx格式轉換 */ @SuppressWarnings("all") public class DocConvert { private static final int environment =Integer.valueOf(Property.getProperty("environment")) ;// 環境 1:windows 2:linux private String fileString;// (只涉及pdf2swf路徑問題) private String outputPath = Property.getProperty("uploadFilePath");// 輸入路徑 ,如果不設置就輸出在默認的位置 private String fileName; private File pdfFile; private File swfFile; private File docFile; public DocConvert(String fileString) { ini(fileString); } /** * 重新設置file * @param fileString */ public void setFile(String fileString) { ini(fileString); } /** * 初始化 * @param fileString */ private void ini(String fileString) { this.fileString = fileString; fileName = fileString.substring(0, fileString.lastIndexOf(".")); docFile = new File(fileString); pdfFile = new File(fileName + ".pdf"); swfFile = new File(fileName + ".swf"); } /** * 轉為PDF * @param file */ private void doc2pdf() throws Exception { System.out.println("pdf轉換,,,,,,,,,,,,,,,");System.out.println("PDF文件路徑"+docFile);if (docFile.exists()) { if (!pdfFile.exists()) { // 調用openoffice服務線程String command = "C:/Program Files (x86)/OpenOffice 4/program/soffice.exe -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\"";Process p = Runtime.getRuntime().exec(command);// 連接openoffice服務// OpenOfficeConnection connection = new SocketOpenOfficeConnection(Integer.valueOf(Property.getProperty("port"))); //服務端口 portOpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);try { connection.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(docFile, pdfFile); // close the connection connection.disconnect(); // 關閉進程p.destroy();System.out.println("****pdf轉換成功,PDF輸出:" + pdfFile.getPath()+ "****1"); } catch (java.net.ConnectException e) { e.printStackTrace(); System.out.println("****swf轉換器異常,openoffice服務未啟動!****2"); throw e; } catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) { e.printStackTrace(); System.out.println("****swf轉換器異常,讀取轉換文件失敗****3"); throw e; } catch (Exception e) { e.printStackTrace(); throw e; } } else { System.out.println("****已經轉換為pdf,不需要再進行轉化****4"); } } else { System.out.println("****swf轉換器異常,需要轉換的文檔不存在,無法轉換****5"); } } /** * 轉換成 swf */ @SuppressWarnings("unused") private void pdf2swf() throws Exception { System.out.println("swf轉換。。。。。。。。。。。。。。"+swfFile.getPath());Runtime r = Runtime.getRuntime(); if (!swfFile.exists()) { if (pdfFile.exists()) {if (environment == 1) {// windows環境處理 try { //exePath+" "+pdfFile.getPath()+" -o "+swfFile.getPath()+" -T 9 -t -s storeallcharacters"//String paths=URLEncoder.encode(swfFile.getPath(), "UTF-8");Process p = r.exec(Property.getProperty("swfPath")+" "+ pdfFile.getPath() + " -o "+ swfFile.getPath() + " -T 9");System.out.println("---"+Property.getProperty("swfPath")+" "+ pdfFile.getPath() + " -o "+ swfFile.getPath() + " -T 9");System.out.print(loadStream(p.getInputStream())); System.err.print(loadStream(p.getErrorStream())); System.out.print(loadStream(p.getInputStream())); System.err.println("****swf轉換成功,文件輸出:" + swfFile.getPath() + "****6"); /* if (pdfFile.exists()) { pdfFile.delete(); } */ } catch (IOException e) { e.printStackTrace(); throw e; } } else if (environment == 2) {// linux環境處理 try { ///weblogic/wls1036/第四部分線性代數.pdf /weblogic/wls1036/1ssss1.swfStringBuffer file=new StringBuffer();file.append("pdf2swf -o ");file.append(swfFile.getPath());file.append(" -T -z -t -f ");file.append(pdfFile.getPath());file.append(" -s languagedir=/var/share/xpdf/xpdf-chinese-simplified -s flashversion=9"); // pdf2swf -o /var/lib/uploadsdsdf.swf -T -z -t -f /var/lib/upload/64d2020c24be4ab9989f82e874edd33f.pdf -s languagedir=/var/share/xpdf/xpdf-chinese-simplified -s flashversion=9 // String[] command = { "sh", "-c", "pdf2swf "+pdfFile.getPath() // + " -o " + swfFile.getPath() + " -T 9"};String[] command = { "/bin/sh", "-c", "pdf2swf "+pdfFile.getPath()+" "+swfFile.getPath()};// String command = "pdf2swf -z -s flashversion=9 " + pdfFile.getPath()+ " -o " + swfFile.getPath();System.out.println(command+" path"); // String[] command = { "/bin/sh", "-c", "pdf2swf "+pdfFile.getPath()+" "+swfFile.getPath()}; // Process p = r.exec("pdf2swf " + pdfFile.getPath() // + " -o " + swfFile.getPath() + " -T 9"); // System.out.println(command.toString()+"path"); // Process p=r.exec(command.toString());Process p=Runtime.getRuntime().exec(command);System.out.print(loadStream(p.getInputStream())); System.err.print(loadStream(p.getErrorStream())); System.err.println("****swf轉換成功,文件輸出:" + swfFile.getPath() + "****7"); /*if (pdfFile.exists()) { pdfFile.delete(); } */ } catch (Exception e) { e.printStackTrace(); throw e; } } } else { System.out.println("****pdf不存在,無法轉換****8"); } } else { System.out.println("****swf已經存在不需要轉換****9"); } } static String loadStream(InputStream in) throws IOException { int ptr = 0; in = new BufferedInputStream(in); StringBuffer buffer = new StringBuffer(); while ((ptr = in.read()) != -1) { buffer.append((char) ptr); } return buffer.toString(); } /** * 轉換主方法 */ public boolean conver() { if (swfFile.exists()) { System.out.println("****swf轉換器開始工作,該文件已經轉換為swf****10"); return true; } if (environment == 1) { System.out.println("****swf轉換器開始工作,當前設置運行環境windows****11"); } else { System.out.println("****swf轉換器開始工作,當前設置運行環境linux****12"); } try { doc2pdf(); pdf2swf(); } catch (Exception e) { e.printStackTrace(); return false; } if (swfFile.exists()) { return true; } else { return false; } } /** * 返回文件路徑 * @param s */ public String getswfPath() { if (swfFile.exists()) { String tempString = swfFile.getPath(); tempString = tempString.replaceAll("\\\\", "/"); return tempString; } else { return ""; } } /** * 設置輸出路徑 */ public void setOutputPath(String outputPath) { this.outputPath = outputPath; if (!outputPath.equals("")) { String realName = fileName.substring(fileName.lastIndexOf("/"), fileName.lastIndexOf(".")); if (outputPath.charAt(outputPath.length()) == '/') { swfFile = new File(outputPath + realName + ".swf"); } else { swfFile = new File(outputPath + realName + ".swf"); } } } }

 

總結

以上是生活随笔為你收集整理的uploadify文件上传以及预览的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 最新国产精品 | 色哥网 | 男生坤坤放进女生坤坤里 | 久久中文字幕人妻熟av女蜜柚m | 日日干日日操 | 国产精品无码av无码 | 欧美日韩在线一区二区 | а√天堂资源在线 | 伊人啪啪 | 亚洲AV无码精品黑人黑人 | 99在线观看免费视频 | 精品国产美女 | 久久精品亚洲天堂 | 久久y| 已满十八岁免费观看全集动漫 | 永久av| 久久99久久99精品免观看软件 | 人妻色综合网站 | 光棍影院一区二区 | 国产精品免费精品一区 | 亚洲色图网址 | 97在线视频免费观看 | 老司机在线永久免费观看 | 一区二区在线观看视频 | 奇米精品一区二区三区在线观看一 | 日本www在线播放 | 无码精品人妻一区二区三区影院 | 亚洲图片三区 | 四虎影视网 | 久久精品一二 | 69av网 | 含羞草一区二区三区 | 欧美一级xxx| 国产视频97 | 香蕉视频免费在线 | 一级片在线免费观看 | 色综合久久久久久 | 中文字幕视频免费观看 | 青娱乐超碰在线 | 国产手机在线视频 | 国产精品欧美激情 | 亚洲日b视频 | 欧美大白bbbb与bbbb | 人妻换人妻仑乱 | 全部孕妇毛片丰满孕妇孕交 | 美女赤身免费网站 | 制服丝袜手机在线 | 狠色综合7777夜色撩人 | 欧美色图五月天 | 三大队在线观看 | 乱日视频| 欧美成人国产va精品日本一级 | 日韩黄色片在线观看 | 超碰av在线 | 一级视频在线免费观看 | 一起操网站 | 欧美成年人视频在线观看 | 老头老太做爰xxx视频 | 女女互慰揉小黄文 | 狠狠干夜夜骑 | 国产中文一区 | 美日韩av| 欧美一区二区三区在线免费观看 | 亚洲24p| 羞羞动漫免费观看 | 男人添女人囗交视频 | 中文字幕在线欧美 | jizz中国少妇 | 免费av大片 | 香蕉av一区二区三区 | 午夜av中文字幕 | 视频二区在线 | 91视频看看 | 亚洲毛片一级 | 岛国精品在线 | 久久精品久久精品久久精品 | 欧美性生活免费视频 | 婷婷亚洲综合五月天小说 | 国偷自拍第113页 | 五月天婷婷激情视频 | 狠狠操伊人 | 人妻无码中文久久久久专区 | 日本欧美一级 | jul023被夫上司连续侵犯 | 欧美成网站 | 啪啪免费视频网站 | 精品国产区 | www.亚洲色图 | 久久久国产精品成人免费 | 黄色成人影视 | 午夜欧美在线 | 色国产视频 | 日韩一区二区三区免费视频 | 伊人资源网 | 日本小视频网站 | 黄网站免费在线观看 | 人人艹人人 | 国产又粗又猛又爽又黄的网站 | 日韩av网址在线观看 |