首页 > 解决方案 > 在另一个 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" 的图像。我该怎么做?

标签: javascriptjqueryhtml

解决方案


很多可能性。取决于您的应用范围和要求。

选项 1 - 使用数据库

将上传的图片从第一页存储到数据库。数据库可以是任何东西——MySql、MSSQL 等。第二页从数据库中读取图片内容。

选项 2 - 使用内存缓存

您可以简单地将图片存储在分布式内存缓存中,例如memcachedredis

选项 3 - 使用文件系统

对于非常琐碎的应用程序(单个 Web 服务器),使用本地文件系统作为数据存储。我不会推荐这个

希望这可以帮助。


推荐阅读