Andy E 是正确的,没有基于 HTML 的方法可以做到这一点*;但如果你愿意使用 Flash,你可以做到。以下内容在安装了 Flash 的系统上可靠运行。如果您的应用程序需要在 iPhone 上运行,那么您当然需要一个基于 HTML 的后备解决方案。
*(2013 年 4 月 22 日更新: HTML 现在在 HTML5 中支持此功能。请参阅其他答案。)
Flash 上传还有其他优点——Flash 使您能够在上传大文件时显示进度条。(我很确定 Gmail 就是这样做的,通过在幕后使用 Flash,虽然我可能错了。)
这是一个示例 Flex 4 应用程序,它允许用户选择一个文件,然后显示它:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               creationComplete="init()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Button x="10" y="10" label="Choose file..." click="showFilePicker()" />
    <mx:Image id="myImage" x="9" y="44"/>
    <fx:Script>
        <![CDATA[
            private var fr:FileReference = new FileReference();
            // Called when the app starts.
            private function init():void
            {
                // Set up event handlers.
                fr.addEventListener(Event.SELECT, onSelect);
                fr.addEventListener(Event.COMPLETE, onComplete);
            }
            // Called when the user clicks "Choose file..."
            private function showFilePicker():void
            {
                fr.browse();
            }
            // Called when fr.browse() dispatches Event.SELECT to indicate
            // that the user has picked a file.
            private function onSelect(e:Event):void
            {
                fr.load(); // start reading the file
            }
            // Called when fr.load() dispatches Event.COMPLETE to indicate
            // that the file has finished loading.
            private function onComplete(e:Event):void
            {
                myImage.data = fr.data; // load the file's data into the Image
            }
        ]]>
    </fx:Script>
</s:Application>