[英]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.