[英]Fetch images from folder
I have the following code that fetches images from Flickr, and I want to change it to fetch images from a folder (without the Flickr API). 我有以下代码可从Flickr获取图像,并且我想将其更改为从文件夹中获取图像(不使用Flickr API)。
I need help. 我需要帮助。 I don't know how to do it.
我不知道该怎么做。
var api_flickr = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";
// fetch images from Flickr
function fetch_images() {
$.getJSON(api_flickr, {
tags: $("#searchinput").val(),
tagmode: "any",
format: "json"
})
.done(function(data) {
$.each(data.items, function(i, item) {
var url = item.media.m;
var title = item.title;
var elem = $("<div class='my show'><img src='"+url+"'/><div>"+
title+"</div>");
images.append(elem);
});
// add more-div and resize
images.append($("#morediv").clone().removeAttr("id"));
resize_images();
});
}
To fetch image from a folder, you may be use ajax/jquery if want javascript. 要从文件夹中获取图像,如果需要JavaScript,可以使用ajax / jquery。
Here I've done this using PHP. 在这里,我已经使用PHP做到了这一点。 You can test this also.
您也可以对此进行测试。
<?php
$imagesDir = 'images\\';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
foreach($images as $key=>$value)
{
echo "<img src='$value' style='margin:10px'>";
}
?>
There is an folder called images
. 有一个名为
images
的文件夹。 Then fetch the images using the php glob function . 然后使用php glob函数获取图像。
Note : Code is tested and working in my site
注意: 代码已经过测试 ,可以在我的网站上运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.