Html IE8文件上传时的空白文件名

Html IE8文件上传时的空白文件名,html,file-upload,internet-explorer-8,Html,File Upload,Internet Explorer 8,我试图上传一个图像到我们的服务器,它可以在Chrome、Firefox和IE9上运行,但不能在IE8上运行。请求中的文件名在IE8中显示为空白,但在Chrome中不显示。对于IE8,服务器检索的文件为0千字节(应为219kb) HTML <form action="$!toolsServiceUrl" enctype="multipart/form-data" method="post" id="left-section" class="section right-border conta

我试图上传一个图像到我们的服务器,它可以在Chrome、Firefox和IE9上运行,但不能在IE8上运行。请求中的文件名在IE8中显示为空白,但在Chrome中不显示。对于IE8,服务器检索的文件为0千字节(应为219kb)

HTML

<form action="$!toolsServiceUrl" enctype="multipart/form-data" method="post" id="left-section" class="section right-border container">
    <input type="hidden" name="okRedirectURL" value="$!okRedirect" />
    <input type="hidden" name="errorRedirectURL" value="$!errorRedirect" />
    <input type="hidden" name="updateSection" value="LOGO_AND_MESSAGE" />
    <input type="hidden" name="loginGuid" value="$!loginGuid" />
    <input id="current-file" class="file hide" type="file" accept="image/*" name="file"/>
    <a id="upload-now" class="btn upload open-file">$!INTL_UploadNew</a>
    <input href="#" class="btn btn-primary submit-for-review" type="submit" value="$!INTL_SubmitForReview" />
</form>
IE8请求有效负载

------WebKitFormBoundaryhaQZT4Syn2OCktxQ
Content-Disposition: form-data; name="file"; filename="wallpaper-2055060.jpg"
Content-Type: image/jpeg
-----------------------------7dc230b1a0a3a
Content-Disposition: form-data; name="file"; filename=""
Content-Type: application/octet-stream
(我省略了请求有效载荷中所有不相关的数据)


我需要它在IE8上工作,因为我们有相当多的用户使用IE8。

从远程机器上尝试同样的方法,可能会得到不同的结果。IE8中有一个关于文件上传的“安全特性”(bug),导致他们无法发送被上传文件的正确路径。据我所知,这只是本地访问站点时的一个问题

有关详细信息,请访问此网站:


从远程计算机上看,如果在浏览器首选项中将站点添加到受信任的站点,则应该可以。但在本地它仍然无法工作。

很可能您隐藏了文件输入字段,然后使用javascript触发单击事件以打开文件对话框。IE假定单击是不安全的,不会发送到服务器

为了避免这种情况,您需要单击实字段或创建一个
,这也将触发“安全”单击事件

您的代码可能如下所示:

<form action="$!toolsServiceUrl" enctype="multipart/form-data" method="post" id="left-section" class="section right-border container">
   ...
   <input id="current-file" class="file hide" type="file" accept="image/*" name="file"/>
   <label for="current-file" id="upload-now" class="btn upload open-file">$!INTL_UploadNew</label>
   ...
</form>

...
$!INTL_上传新
...

您也不应使用
显示:无
隐藏文件输入字段,否则不会触发标签单击。取而代之的是,你做了一些类似于
position:absolute;左:-9999px
隐藏在可见的查看端口。

您是从本地主机访问此文件,还是远程连接到您的站点?@Jaambageek该站点位于内部网络上。上载服务器是同一网络上的另一台主机,尽管在本例中,我在本地运行上载服务器进行调试。IE8允许您在单击/更改事件之外读取文件输入,但较新的浏览器不允许您访问文件名或文件数据。