获取图片上传后的路径
用户通过 选择图片后,前端可能需要获取其路径。默认情况下, 只会提供文件的名称。
解决方案
可以使用 javascript 获取文件的绝对路径。具体步骤如下:
立即学习“Java免费学习笔记(深入)”;
代码示例
html:
<form name="thisform" method="post" action="action_url" id="thisform" enctype="multipart/form-data"> <input type="file" name="thefile" onchange="document.getelementbyid('thefilepath').value=this.value"> <input type="hidden" id="thefilepath" name="thefilepath" value=""> </form>
action 代码:
String filePath = request.getParameter("theFilePath");
通过这种方式,前端即可获取图片上传后的绝对路径。
以上就是如何通过 JavaScript 获取图片上传后的绝对路径?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号