Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display the most recent jpg

Status
Not open for further replies.

bopritchard

Programmer
Jan 27, 2003
199
US
i have a directory of images that are time stamped in their name like this cam20030829103721843.jpg...they get added to every few minutes...what i want to do is display only the most recent file as an image..

so img src=newestfile.jpg

thanks
 
Here's a little clip from an image directory lister. You can tweak the last few lines to obtain the last element in the array to get your most recent image. I'm sure there is an easier way to get the most recent file by reading the system date but since you didn't share the URL for your dirty web cam, this is all I choose to offer. ;)

Code:
// The subdirectory that stores cam shots
$short = "/camshots";
// The full system path of the cam shot subdirectory
$long = "/[URL unfurl="true"]www/joeuser/htdocs/camshots";[/URL]

function showdirectory($short,$long) {
  print (&quot;This lists images in a directory:<br>&quot;);
  if (is_dir($long))
  {
  if ($dh = opendir($long))
  {
  while (($filename = readdir($dh)) !== false)
  {
  if (($filename != &quot;.&quot;) && ($filename != &quot;..&quot;))
  {
  $files[]=&quot;$filename&quot;;
  }
  }
  closedir($dh);
  }
  }
  natcasesort($files);
  foreach ($files as $myfilename) {
  print (&quot;<a href=\&quot;$short/$myfilename\&quot;>$myfilename</a><br>&quot;);
  }
}

- - picklefish - -

Why is everyone in this forum responding to me as picklefish?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top