简体   繁体   English

如何在事件 oninput 上的文件输入值之前添加值

[英]How to add value before file input value on event oninput

I am trying to add text "img/books/" before the image file name in the file upload, to be concatenated and submitted this way the the db: "img/books/imageName.png", but this is not working :/我试图在文件上传中的图像文件名之前添加文本“img/books/”,以这种方式连接并提交db:“img/books/imageName.png”,但这不起作用:/

<script type="text/javascript">
   function addDir()
   {
        const imgDir = 'img/books/'
        document.getElementById('book_img').value =  imgDir +
        document.getElementById('book_img').file.value

   }
</script>

here is html code这是html代码

<label for="fname">Book Image</label><br>
<input type="file" name="book_img" id="book_img" oninput="addDir()">

It is not possible to change or set the value of the input file.无法更改或设置输入文件的值。 This is for user safety reasons.这是出于用户安全的考虑。 However, it is possible to read the file name, associate it with the required address and save it in the input hidden.但是,可以读取文件名,将其与所需地址相关联并将其保存在输入隐藏中。 The backend must be prepared for this.后端必须为此做好准备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM