how do i show all .jpg pictures in a folder but i

2020-04-22 01:43发布

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: 2013] [mo: 04] [Day: 13] [Hour: 14] [min: 57] [Sec: 14]
(IPCAM)_0_20130413145719_63.jpg [Year: 2013] [mo: 04] [Day: 13] [Hour: 14] [min: 57] [Sec: 19]
(IPCAM)_0_20130413145723_64.jpg [Year: 2013] [mo: 04] [Day: 13] [Hour: 14] [min: 57] [Sec: 23]
(IPCAM)_0_20130413145727_65.jpg [Year: 2013] [mo: 04] [Day: 13] [Hour: 14] [min: 57] [Sec: 27]

Can you see the pattern in the image names? I am curently using this script to display them:

<?php 
$dirname = "./";
$images = glob($dirname."*.jpg");
foreach($images as $image) {
echo '<img src="'.$image.'" /><br />';
}
?>

I would like to have a calendar so I can select the [Day: **] and get all the pictures that were taken that day.

I hope someone can help me with this code.

标签: php html
5条回答
成全新的幸福
2楼-- · 2020-04-22 02:07

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>
        <meta charset="utf-8" />
        <title>StackOverflow Answer</title>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
        <link rel="stylesheet" href="/resources/demos/style.css" />
        <script>
          $(function() {
          $( "#datepicker" ).datepicker({
                  onSelect: function(date, instance){
                      window.location = "?date="+date;
                  }
              });
          });
        </script>
    </head>
    <body>
        <p>Date: <input type="text" id="datepicker" /></p>
        <?php
            if($_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($images as $image)
                {
                    if(strpos($image, $formattedDate))
                    {
                        echo '<img src="'.$image.'" /><br />';
                    }
                }
            }
        ?>
    </body>
</html>
查看更多
够拽才男人
3楼-- · 2020-04-22 02:12

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($images as $image) {
    if (strstr($image, 'Day' + $daynum))
    {
        echo '<img src="'.$image.'" /><br />';
    }
}
?>
查看更多
看我几分像从前
4楼-- · 2020-04-22 02:17

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

查看更多
聊天终结者
5楼-- · 2020-04-22 02:26

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');
查看更多
欢心
6楼-- · 2020-04-22 02:32

I didnt test this, but:

<?php 
$dirname = "./";
$images = glob($dirname."*.jpg");
$date = "[Year: ".$_GET['y']."] [mo:".$_GET['m']."] [Day: ".$_GET['d']."]";
foreach($images as $image) {
    if (strpos($image,$date) !== false) {
        echo '<img src="'.$image.'" /><br />';
    }
}
?>

request goes : ?y=2013&m=12&day=13

查看更多
登录 后发表回答