浏览按钮,无需在html中上传文件 [英] Browse button without file upload in html

查看:145
本文介绍了浏览按钮,无需在html中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有脚本,该脚本会获取路径并将一些文件复制到其中.我想要的是:我想要一个浏览按钮,当用户单击它时,他将能够选择要移动文件的文件夹,然后按Enter.有可能吗?

I have script, which takes path and copy some files into it. What I want is: I want to have browse button and when user clicks it, he will be able to just select folder he wants to move files to and hit enter. Is it possible?

推荐答案

由于此功能会暴露出安全性问题(即能够记录用户的文件目录),因此这是不可能的.当用户浏览文件时,浏览器将创建对话框,并且该信息的将仅中继所选文件的内容.

This just isn't possible because of security issues that would be exposed by this functionality, i.e. being able to log the user's file directories. When a user browses for a file, the dialog is created by the browser and none of this information is relayed back, only the contents of the selected file.

我能想到的唯一解决方案而不是按ActiveX或类似的方法,是迫使用户从所选目录中选择一个文件并上传.这具有明显的缺点,即他们可能不希望其文件被上载,并且他们可能在所需的文件夹中没有任何文件.但是,假设a)他们有一个文件,b)他们不关心您如何处理该文件,您可以:

The only solution I can think of without hitting up ActiveX or similar is to force the user to select a file from within their chosen directory and upload it. This has obvious drawbacks in that they may not want their files to be uploaded and also that they may not have any files within their desired folder. However, assuming that a) they have a file and b) that they don't care about how you deal with that file you can:

<form name="folderForm">
    <input type=file name="file">
    <input type=text name="folderLocation">
    <input type=button value="Get Folder" onclick="javascript:GetFolder();">
</form>

function GetFolder() {
    document.folderForm.folderLocation.value=document.folderForm.file.value;
}

然后在服务器端,您可以解析folderLocation的值以删除最后一个/之后的文件名,或者根据需要在GetFolder()中执行此操作.

Then on the server side you can parse the value of folderLocation to remove the file name after the last / or do this in GetFolder() if you wish.

这篇关于浏览按钮,无需在html中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆