Display selected file in html input before upload

血红的双手。 提交于 2020-01-25 18:27:44

问题


How can i show file that i select thru browse field into html input? I want to see file that i selected before i press upload?

Here is my code:

          <input id="uploadFile" name="uploadFileOne" type="text" disabled="disabled" value="<?php echo $file_name; ?>" placeholder="EWIS" class="name-info-form file-witdth" />              
          <input class="upload" type="file" id="uploadOne" name="uploadOne" value="Select File"/ >

回答1:


<form>
  <input class="upload" type="file" id="uploadOne" name="uploadOne" onchange="setfilename(this.value);" value="Select File"/ >
  <input id="uploadFile" name="uploadFileOne" type="text" disabled="disabled" placeholder="EWIS" class="name-info-form file-witdth" />
</form>

remove value=<?php echo $file_name; ?> and use the javascript for set the name of file in textbox

<script>
  function setfilename(val)
  {
    var fileName = val.substr(val.lastIndexOf("\\")+1, val.length);
    document.getElementById("uploadFile").value = fileName;
  }
</script>

when you select the file using browse button, onchange event will fire and set the file name in text-box :)



来源:https://stackoverflow.com/questions/34841434/display-selected-file-in-html-input-before-upload

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