上傳之前獲取文件的高度寬度我有天冬氨酸:在我的網頁表單FileUpload控件。使用Javascript/Asp.net
在的OnChange()事件的FileUpload控制,執行JavaScript函數
<asp:FileUpload ID="fUpload" runat="server" Style="visibility: hidden;width:1px" onchange="callme(this)"/>
JavaScript函數:
function callme(oFile) {
document.getElementById('<%=txtFilePath.ClientID%>').value = oFile.value;
ReadImage(oFile.value);
}
ReadImage功能應該閱讀該文件,並告訴高度所選文件的寬度和大小,並在文件不是圖像時顯示錯誤消息。
function ReadImage(_file)
{
var reader = new FileReader();
var image = new Image();
image.src = 'file://' + _file;
image.onload = function() {
alert('Step 2');
var w = this.width,
h = this.height,
t = file.type,
n = file.name,
s = ~ ~(_file.size/1024) + 'KB';
alert('<img src="' + this.src + '"> ' + w + 'x' + h + ' ' + s + ' ' + t + ' ' + n + '<br>');
};
image.onerror= function()
{
alert('Invalid file type: '+ _file.type);
};
}
的ReadImage()函數應該閱讀選擇的文件,並上傳到服務器之前獲得高度,寬度和大小的文件。
如何可以做到這一點?我做錯了什麼。
什麼是'_file'的價值? – TryingToImprove 2014-11-25 09:03:38
用戶機器...除權任何本地文件路徑: 「C:\用戶\ amit_shelke \圖片\ as.jpg」 – 2014-11-25 09:07:46
你確定它是不是'C:/ fakepath/as.jpg'? – TryingToImprove 2014-11-25 09:49:38