Skip to Content
JAVASCRIPT網頁應用程式設計
book

JAVASCRIPT網頁應用程式設計

by Alex MacCaw
January 2013
Intermediate to advanced
332 pages
5h 23m
Chinese
GoTop Information, Inc.
Content preview from JAVASCRIPT網頁應用程式設計
100
|
第七章
if (window.File && window.FileReader && window.FileList) {
// 支援此 API
}
取得檔案資訊
基於安全性的考量,HTML5 的檔案處理機制,僅能存取由使用者選取的檔案。目前
使用者可以透過下列幾種不同方式選取檔案:將檔案拖進瀏覽器裡、利用檔案選取欄
位,或是利用複製貼上方式貼進網頁應用程式裡。目前已經有一些人能用 JavaScript
發出完整的檔案管理系統(
http://www.html5rocks.com/en/tutorials/file/filesystem/
),不過
JavaScript 程式對檔案的存取,實際上都會被侷限在一塊封閉的沙盒區域(sandbox
內。理由很簡單:如果能讓 JavaScript 程式隨心所欲的存取作業系統裡所有檔案,勢必
將成為很嚴重的安全性漏洞。
HTML5 是用
File
物件來代表檔案,該物件裡有三個屬性:
name
檔案名稱(唯讀的字串屬性值)
size
檔案大小(唯讀的數值屬性值)
type
檔案的 MIME 類型(唯讀的字串屬性值),如果無法判斷 MIME 類型為何,會回傳
空字串(“”)
基於安全性的考量,我們無法取得實體檔案存放路徑。
如果需要用到多個檔案,可以用
FileList
物件,你可以把它想成是存放
File
物件的
陣列。
檔案選取欄位
檔案選取欄位,是以往讓使用者上傳檔案的標準做法,也是從網頁誕生以來就一直存在
的功能。HTML5 已針對這項功能做了改良,並修正了一些缺點
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

Ethan Brown, 武舎 広幸, 武舎 るみ
PHP编程:第4版

PHP编程:第4版

Kevin Tatroe, Peter MacIntyre
Strange Code

Strange Code

Ronald T. Kneusel
Perfecting Your Thinking Skills

Perfecting Your Thinking Skills

MIT Sloan Management Review

Publisher Resources

ISBN: 9789862766811