【问题标题】:Display File Path instead of just file name (jquery)显示文件路径而不仅仅是文件名(jquery)
【发布时间】:2014-07-25 02:37:19
【问题描述】:

当用户上传他们的文件时,我想显示该文件的文件路径。

注意:我,服务器,不需要文件路径,我只想为用户信息显示它。

我知道存在安全问题,但是否可以只显示?

我该怎么做?

到目前为止:

        <form method="post" id="fileinfo" name="file" onsubmit="return submitForm();">
            <label>Select a file:</label>
            <input type="file" name="file"/>
        </form>

        <input type="button" value="Submit!!" id="myButton" />

所以当他们选择一个名为 test.txt 的文件时,

我的 ui 将显示 C://path//text.txt 而不仅仅是 test.txt

谢谢!

【问题讨论】:

  • 看看This Post
  • 从服务器端脚本返回文件路径,这将完成上传
  • 已经试过了,可惜不行
  • @valentin 你能详细说明一下吗?例子会很好
  • @user3773673 好的,如果您愿意,我可以给您写一个非常详细的答案。您的服务器端脚本语言是什么? PHP?

标签: jquery html file-upload


【解决方案1】:

这是显示路径的一种方式

Fiddle

$('#file').change(function(){
    var fileName = $(this).val();
    $('#file_path').text(fileName);
});

主要问题是您无法编辑文件输入中的文本,下面显示了另一种 hack:

Fiddle

<div class="hide_text">
    <input id="file" type="file" name="file" />
</div>

.hide_text{
    display:inline-block;
    width:85px;
    overflow:hidden;
}

【讨论】:

    猜你喜欢
    • 2022-07-15
    • 2012-01-21
    • 1970-01-01
    • 2016-08-16
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多