How Do I Show All .jpg Pictures In A Folder But I Want Only Pictures From Today
I hope I can make myself clear. I have a webcam that sends a picture at every second to my website. They all sum up in the folder like this: (IPCAM)_0_20130413145714_62.jpg [Year:
Solution 1:
Did you try
$dayInQuestion = '20130413';
glob($dirname."(IPCAM)_0_".$dayInQuestion."*.jpg");
with your date?
Ref: PHP manual for more options eg., http://www.php.net/manual/en/function.glob.php#110340
Solution 2:
Make a string for today and then match it against your images. So instead of pulling all images (*) we match the image name against our today string:
date_default_timezone_set('America/New_York');
$today = date("Ymd");
$files = glob($dirname.'*'.$today.'*.jpg');
Solution 3:
As long as the photos use a consistent naming scheme you should be able to filter them by the filename using strstr. Something like this, maybe:
<?php$dirname = "./";
$daynum = "13";
$images = glob($dirname."*.jpg");
foreach($imagesas$image) {
if (strstr($image, 'Day' + $daynum))
{
echo'<img src="'.$image.'" /><br />';
}
}
?>
Solution 4:
here is my answer using the jQuery date picker:
working example can be found here
choose 13th April 2013 in the example
<!DOCTYPE html><html><head><metacharset="utf-8" /><title>StackOverflow Answer</title><linkhref="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /><scriptsrc="http://code.jquery.com/jquery-1.9.1.js"></script><scriptsrc="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script><linkhref="/resources/demos/style.css" /><script>
$(function() {
$( "#datepicker" ).datepicker({
onSelect: function(date, instance){
window.location = "?date="+date;
}
});
});
</script></head><body><p>Date: <inputtype="text"id="datepicker" /></p><?phpif($_GET)
{
$dirname = "IPCam/";
$images = glob($dirname."*.jpg");
$date = str_replace('/', '', $_GET['date']);
$day = substr($date, 2, 2);
$month = substr($date, 0, 2);
$year = substr($date, 4, 4);
$formattedDate = $year.$month.$day;
foreach($imagesas$image)
{
if(strpos($image, $formattedDate))
{
echo'<img src="'.$image.'" /><br />';
}
}
}
?></body></html>
Post a Comment for "How Do I Show All .jpg Pictures In A Folder But I Want Only Pictures From Today"