中山php|最优网络中山做网站 中山php建站

最优良人

Posts Tagged With: file

JS获取file上传文件路径,后缀,大小,文件名

2012/08/16 at 11:58 » Comments (184)

/** *函数描述:获取input type=file的图像全路径 * @obj input type=file的对象 **/ function getFullPath(obj) { if(obj) { //ie if (window.navigator.userAgent.indexOf("MSIE")>=1) { obj.select(); return document.selection.createRange().text; } //firefox else if(window.navigator.userAgent.indexOf("Firefox")>=1) { if(obj.files) { return obj.files.item(0).getAsDataURL(); } return obj.value; } return obj.value; } }   <input type="file" onchange="document.getElementById('img').src=getFullPath(this);" >   =========================================================================     #判断IE还是Firefox function getFullPath(obj) { if(obj) { //ie if (window.navigator.userAgent.indexOf("MSIE")>=1) { obj.select(); return document.selection.createRange().text; } //firefox else if(window.navigator.userAgent.indexOf("Firefox")>=1) { if(obj.files) { return obj.files.item(0).getAsDataURL(); } return obj.value; } return obj.value; } }       #判断后缀名 function yulan(){ var filePath =getFullPath(document.getElementById('UpFile')); var fileText =filePath.substring(filePath.lastIndexOf("."),filePath.length); var ...more »