赞
踩
<tr class="defaultBGColor"> <td class="editLabel">テーマファイル:</td> <td ><input type="file" name="theme_path" id="themePath"/> <font id="themepathFont" color="red">*</font></td> </tr
>
var themePath=document.getElementById('themePath'); themePathDiy.value=themePath.files[0].getAsDataURL();//传到后台处理//处理代码见下面的java代码
String fileData = request.getParameter("themePathDiy"); fileData=parse64Base(fileData);//+public String parse64Base(String str){ String re=str.split(",")[1]; BASE64Decoder decoder=new BASE64Decoder(); try { byte[]b=decoder.decodeBuffer(re); return new String(b); }catch(Exception e){return null;} }
<!doctype html public "-//w3c//dtd html 4.01//en" "http://www.w3.org/tr/html4/strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>New file input tester.</title></head><body><input id="myfile" type="file" /><br /><img src="" alt="Image to be upload." /><div id="info"></div><script type="text/javascript">var dFile = document.getElementById('myfile');var dImg = document.getElementsByTagName('img')[0];var dInfo = document.getElementById('info');dFile.onchange = function(){ if(!dFile.value.match(/.jpg|.gif|.png|.bmp/i)){alert('File type must be: .jpg, .gif, .bmp or .png !');return;} if(dFile.files){ dImg.src = dFile.files[0].getAsDataURL(); }else if(dFile.value.indexOf('\\') > -1 || dFile.value.indexOf('\/') > -1){ dImg.src = dFile.value; }}</script></body></html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。