javascript - 在另一个 html 页面中显示上传的图像
问题描述
我想将 home.html 中上传的图像显示到另一个名为 result.html 的页面。
<div class="custom-file">
<input type="file" class="custom-file-input" name="myfile" onchange="readURL(this);">
<label class="custom-file-label" for="customFile" name="myfile">Choose file</label>
</div>
<div style="text-align: center;">
<input type="submit" class="mybtn" onclick="showInput();">
</div>
我想在 result.html 页面中显示上传的带有 name="myfile" 的图像。我该怎么做?
解决方案
很多可能性。取决于您的应用范围和要求。
选项 1 - 使用数据库
将上传的图片从第一页存储到数据库。数据库可以是任何东西——MySql、MSSQL 等。第二页从数据库中读取图片内容。
选项 2 - 使用内存缓存
您可以简单地将图片存储在分布式内存缓存中,例如memcached或redis。
选项 3 - 使用文件系统
对于非常琐碎的应用程序(单个 Web 服务器),使用本地文件系统作为数据存储。我不会推荐这个。
希望这可以帮助。
推荐阅读
- javascript - 从文本框中获取输入并使用该文本重定向以执行谷歌搜索
- javascript - 使用变量作为属性 - 错误:意外的令牌 [
- python - python csv - 如果第 1 列和第 2 列具有特定值,则打印 CSV 值
- reactjs - 无法解析“C:\Users\HP\Desktop\pics\src\components”中的“axios”
- opc-ua - node opcua - 需要关于客户端如何获取给定 UAObject 节点 ID 的所有变量的示例
- reactjs - 最好的方法是过滤内部数据以进行渲染?
- python - setup(name) 和 Extension(name) 有什么关系
- html - 将文本附加到输入字段而不更改其值?
- c++ - 如何获取字符串向量中某个元素的位置,将其用作整数向量中的索引?(= 线程的原始名称)
- r - 创建没有一个数字的随机矩阵