CCraft Posted July 8, 2006 Share Posted July 8, 2006 Greetings everyone,What I have is a server with some web cam software installed. The software saves images whenever motion is detected. I have an apache/php server going to serve a php page that I want to display the images. Its just a side DIY project at my home. Here is what I have so far.[code]<html><head></head><body><table><?php$dir = ".";if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (preg_match("/.jpg/", $file)) { $exif = exif_read_data($file, 0, true); echo "<tr>"; echo "<td valign=top><a href=$dir/$file><img src=$dir/$file width=250 height=200></a><td>"; echo "<td valign=top><font size=-1>"; echo "File: <b>" . $exif['FILE']['FileName'] . "</b><br/>"; echo "Size" . ': ' . filesize($file) . ' bytes' . "<br/>"; echo date ("F d Y H:i:s.", filemtime($file)); echo "</font></td>"; echo "</tr>"; } } closedir($dh); }}?></table></body></html> [/code]I am trying to do 2 things that I haven't been able to figure out. 1) I don't want to display any images will a filesize less than 100000 bytes. 2) I want to order the images by their creation date with the most recent at the top. I just have all the images and the script in the root directory of my web sever. Any help with figuring this out would be great.Thank you in advance,Chris Quote Link to comment https://forums.phpfreaks.com/topic/14052-image-display-script-help/ Share on other sites More sharing options...
Wildbug Posted July 9, 2006 Share Posted July 9, 2006 You already know about filesize(), so why aren't you using it to filter the results?[code]if (preg_match('/\.jpg$/',$file) && filesize($file) > 100000) { // ....}[/code]If you need to sort data, you can't do it on the fly. You can save it in an array and use the array sorting functions to rearrange the data in the order you want it. Then it can be output in the desired order.For example:[code]function _filesorter($a,$b) { if ($a['date'] == $b['date']) return 0; return ($a < $b) ? -1 : 1;}$imageFiles = array();while (($file = readdir($dh)) !== false) { if (preg_match('/\.jpg$/',$file)) { $exif = exif_read_data($file,0,true); $imageFiles[$file]['date'] = filemtime($file); $imageFiles[$file]['size'] = filesize($file); $imageFiles[$file]['name'] = $exif['FILE']['FileName']; $imageFiles[$file]['path'] = "$dir/$file"; }}// ...uasort($imageFiles,'_filesorter');// ... then print the output ...[/code]I haven't tested that, but you get the idea. You need the extra callback function to sort the multi-dimensional array by one of its values.(Notice the updated regex pattern. You need to escape the period (\.) to actually match a period, and the pattern should also be anchored at the end ($). Your pattern will match *.jpg files, but it will also match "about_jpgs.html," etc.) Quote Link to comment https://forums.phpfreaks.com/topic/14052-image-display-script-help/#findComment-55179 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.