简体   繁体   English

如何从HTML文件夹中获取未知图像?

[英]How to get unknown image from folder in HTML?

I have an image that is uploaded to a directory called "uploads" on my server, is there anyway I can display that image on an HTML page without having to specify the filename of the image? 我的服务器上有一个上传到目录“ uploads”的图像,是否可以在无需指定图像文件名的情况下在HTML页面上显示该图像? Say I want to display the only png image within the directory, is there something like a wildcard that I can use to scan for the image that fits the criteria? 假设我要显示目录中唯一的png图像,是否可以使用通配符之类的东西来扫描符合条件的图像?

Using something like the following pseudocode can allow you to pull all the .png files from your /uploads folder, thus if you only have one file in question it should work fine. 使用类似以下伪代码的内容可以使您从/uploads文件夹中提取所有.png文件,因此,如果您只有一个文件有问题,它应该可以正常工作。 It involves JQuery however. 但是它涉及到JQuery。

var dir = "S/uploads/";
var fileextension = ".png";
$.ajax({
    url: dir,
    success: function (data) {
        $(data).find("a:contains(" + fileextension + ")").each(function () {
            var filename = this.href.replace(window.location.host, "").replace("http:///", "");
            $("body").append($("<img src=" + dir + filename + "></img>"));
        });
    }
});

No, it is not directly possible as that would create vulnerabilities. 不,这不可能直接导致漏洞。 You can hack it, as others have answered if you don't care about security. 您可以破解它,就像其他人回答的那样,如果您不关心安全性。

An alternative would be with scandir() (php) 另一种选择是用scandir()(php)

$dir    = '/your-directory-here/';
$files1 = scandir($dir);

This outputs an array of the files in $dir and you can then sort/isolate however you want. 这将在$dir输出文件数组,然后您可以根据需要进行排序/隔离。 See more: http://php.net/manual/en/function.scandir.php 查看更多: http : //php.net/manual/zh/function.scandir.php

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

相关问题 如何使用html输入标签从用户获取图像并将其存储在树莓派上的文件夹中 - How to get an image from a user and store it in a folder on a raspberry pi using the html input tag 如何使用 express 从另一个文件夹中获取 html 文件? - How can I get html file from another folder with express? 如何在不使用 Webpack 的情况下从公共文件夹获取图像 - How to get image from public folder without using Webpack 如何从已添加到 html 中未知大小的表格的下拉菜单中获取单个值 - How to get individual values from dropdown menus which have been added to a table of unknown size in html 服务器图像文件夹中的jsp html图像字幕 - jsp html image marquee from server image folder 如何从 html 容器的已知宽度获取图像的缩放高度? - How to get scaled height of an image from known width of an html container? 如何从HTML 5文件API获取图像宽度 - How to get the image width from html 5 file API 如何通过javascript从html内容获取图像标签的域名 - how to Get domain name of image tag from html content by javascript 如何从html图像中获取base64编码数据 - How to get base64 encoded data from html image 如何读取文件夹内的文件夹并从每个文件夹中获取 index.html 并作为列表 (li) 标签中的链接传递 - How to read the folders inside a folder and get the index.html from each folder and pass as a link in a list (li) tag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM