【问题标题】:Restrict file browsing to a specific path only仅将文件浏览限制到特定路径
【发布时间】:2014-11-14 09:48:35
【问题描述】:

有没有办法限制文件浏览到特定路径?

<input type="file" name="pic" >

路径可能在本地文件系统中,也可能不在本地文件系统中,也可以在网络或任何其他位置。

可以这样做吗?

我正在使用 JSP+struts 1.x

谢谢

【问题讨论】:

    标签: html file input


    【解决方案1】:

    出于安全原因,您无法设置文件的位置。

    但是您可以通过在输入元素上设置带有 mime-type 的接受属性来限制接受的文件类型。

    <input type="file" name="pic" accept="image/*" />
    

    input element specification

    accept = content-type-list [CI]
     This attribute specifies a comma-separated list of content types that a server
     processing this form will handle correctly. User agents may use this information
     to filter out non-conforming files when prompting a user to select files to be sent
     to the server (cf. the INPUT element when type="file").
    

    【讨论】:

      【解决方案2】:

      没有。你不能。 Web 服务器不能有这样的权限对用户本地文件系统做这样的限制。如果有人能做到这一点,我将其视为黑客行为。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-18
        • 1970-01-01
        相关资源
        最近更新 更多