Input File field to Input Text field

孤街醉人 提交于 2019-11-29 15:29:18

Hook on the change event of the file field.

<form method="post" enctype="multipart/form-data">
    <input type="file" onchange="this.form.filename.value = this.value">
    <input type="text" name="filename">
</form>

Jsfiddle demo. Note that IE6/7 incorrectly gives the full path while other browsers correctly gives only the filename.

This should be possible by creating a new text input element and populating it with the .value property of the file input.

Note, however, that all modern browsers store only the file name in the value property for security reasons. You will not be able to get the full path of the selected file.

Sources: MSDN on IE8

You can't do it without first storing the file on your own server.

The file input control does not contain the file's data. Your browser provides it to you as a placeholder until you submit the file data via a POST form submission.

If you're after the file's path, you also cannot do that (in modern browsers, as Pekka says). The browser does not give that information to client-side scripts. It may provide the filename, however.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!