我们有简单的HTML表单<input type="file">,如下所示:
<form>
<label for="attachment">Attachment:</label>
<input type="file" name="attachment" id="attachment">
<input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
在IE7(可能是所有着名的浏览器,包括旧的Firefox 2)中,如果我们提交像'// server1/path/to/file/filename'这样的文件,它可以正常工作,并提供文件和文件名的完整路径.
在Firefox 3中,它只返回'filename',因为它们有新的"安全功能"来截断路径,如Firefox错误跟踪系统(https://bugzilla.mozilla.org/show_bug.cgi?id=143220)中所述.
我不知道如何克服这个"新功能",因为它导致我的webapp中的所有上传表单停止在Firefox 3上运行.
任何人都可以帮助找到一个解决方案来获取Firefox 3和IE7上的文件路径?
我有以下剃刀代码:
<div class="container">
@Html.ValidationSummary(false)
@using (Html.BeginForm("EncryptFile", "Encryption", new { returnUrl = Request.Url.AbsoluteUri }, FormMethod.Post, new { @id = "encryptionform", @class = "form-horizontal" }))
{
<div class="form-group">
@Html.Label("File", new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" id="encryptfilefield" name="uploadedfile" enctype='multipart/form-data'/>
</div>
</div>
<button type="submit" id="encryptfilebutton">Encrypt</button>
<button id="decryptfilebutton" type="button">Decrypt</button>
<button id="reencryptfilebutton" type="button">Re-Encrypt</button>
}
</div>
Run Code Online (Sandbox Code Playgroud)
当我单击“加密”按钮时,将调用以下控制器代码:
[HttpPost]
public ActionResult EncryptFile(string uploadedfile)
{
/*process the file without uploading*/
return Json(new { status = "success", message = "Encrypted!" });
}
Run Code Online (Sandbox Code Playgroud)
当我单击加密按钮时,我可以执行此操作,但uploadedfile字符串始终以 …