2016-08-19 198 views
1

如何獲取這些圖像值,特別是當我拖動圖像時從控制檯顯示的名稱,大小,類型。並將這些數據顯示到我的特定格Javascript:如何獲取此圖像數據

File {name: "free-windows-10-wallpaper_050549897_263.jpg", lastModified:  
1464238729860, lastModifiedDate: Thu May 26 2016 12:58:49 GMT+0800 (Malay 
Peninsula Standard Time), webkitRelativePath: "", size: 1185535…} 
lastModified : 1464238729860 
lastModifiedDate :Thu May 26 2016 12:58:49 GMT+0800 (Malay Peninsula Standard Time) 
name : "free-windows-10-wallpaper_050549897_263.jpg" 
size : 1185535 
type : "image/jpeg" 
webkitRelativePath : "" 
__proto__ : File 

這是js代碼。

var obj = $('.drag_me'); 

obj.on('dragover', function(e){ 
    e.stopPropagation(); 
    e.preventDefault(); 
    $(this).css('border', '2px solid #39ADCD'); 

}); 

obj.on('drop', function(e){ 
    e.stopPropagation(); 
    e.preventDefault(); 
    $(this).css('border', '2px dotted #39ADCD'); 

    var files = e.originalEvent.dataTransfer.files; 
    var file = files[0]; //<-- I need to get the size, name, image type of this image 
    console.log(file); 

    //upload(file); 
}); 

這樣我就可以顯示這些數據給我的HTML

<div class="drag_here"> 
    <div class="drag_me"> 
     <center id="center_html"> 
      Drag image here 
     </center> 
    </div> 
</div> 
+3

無法訪問使用'file.name','file.lastModified',就在你的'//上傳(文件)'了嗎? –

+0

@DavidR謝謝你,我明白了。 –

回答

1

您可以使用它訪問,

file.name, 
file.lastModified 

注意:你只需要你的//upload(file)語句之前將其列入。

HTH

相關問題