Witam, posiadam kamerę która co jakiś ustalony czas wysyła zdjęcie na serwer FTP, robi to w taki sposób że zapisuje każdego dnia zdjęcia w innym folderze, np. 2013-05-15/"nazwa kamery"/1 (nie da się tego zmienić). Dostałem skrypt który wybiera najnowsze zdjęcie z folderu, ale w tym przypadku nie spełnia on moich oczekiwań. Skrypt składa się z trzech plików:

getImage.php:
  1. <?php
  2. /*
  3.  * To change this template, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. $dirPath = '2013-05-15/"nazwa kamery"/1/';
  8. global $dirPath;
  9. $datesArray = array();
  10. $imagesArray = array();
  11. global $datesArray;
  12. global $imagesArray;
  13. $arrayIndex = $_GET['index'];
  14.  
  15.  
  16. if (is_dir($dirPath)) {
  17. if ($dirHandler = opendir($dirPath)) {
  18. while (($file = readdir($dirHandler)) !== false) {
  19. if ($file != '.' && $file != '..') {
  20. //echo $file.'<br />';
  21. $date = filemtime($dirPath.$file);
  22. $datesArray[$date] = $file;
  23. }
  24. }
  25. }
  26. }
  27. krsort($datesArray);
  28. //print_r($datesArray);
  29. $i = count($datesArray) - 1;
  30. foreach ($datesArray as $key => $value) {
  31. $imagesArray[$i] = $value;
  32. $i--;
  33. }
  34.  
  35. //print_r($imagesArray);
  36. //echo $arrayIndex;
  37. //$imageName = $datesArray[count($datesArray) - $arrayIndex];
  38. //$imageNameTab = split('::', $imageName);
  39. //$imageName = $imageNameTab[1];
  40. //echo $imageName;
  41. $imageName = prepareImgName(count($imagesArray) - 2);
  42. //echo $imageName;
  43.  
  44. if ($fileHandler = fopen($dirPath.$imageName, 'r')) {
  45. header('Pragma: public');
  46. header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
  47. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  48. header('Cache-Control: no-store, no-cache, must-revalidate');
  49. echo $dirPath.$imageName;
  50. }
  51. for ($i = 0; $i < count($imagesArray) - 11; $i++) {
  52. unlink($dirPath.$imagesArray[$i]);
  53. }
  54. function prepareImgName($_index) {
  55. global $imagesArray;
  56. global $dirPath;
  57. $imageName = '';
  58. $imageName = $imagesArray[$_index];
  59. if (!filesize($dirPath.$imageName) > 0) {
  60. //echo 'tutaj';
  61. $_index--;
  62. return prepareImgName($_index);
  63. }
  64. else {
  65. return $imageName;
  66. }
  67. }
  68. ?>

index.php:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <META HTTP-EQUIV="Expires" CONTENT="Tue, 04 Dec 1993 21:29:02 GMT">
  6. <title></title>
  7. <script src="js/jquery-1.2.6.js" type="text/javascript"></script>
  8. <script type="text/javascript">
  9.  
  10. $(document).ready(function() {
  11. });
  12. var t;
  13. function getImage(command) {
  14. var action = command;
  15. if (action != 'stop') {
  16. $.get('getImage.php', function(data){
  17. $("div#imageContainer").replaceWith('<div id="imageContainer"><img src="' + data + '?' + (new Date()).getTime() + '" alt="" /></div>');
  18. if (data) {
  19. t = setTimeout(function(){getImage(action)},4000);
  20. }
  21. })
  22. }
  23. }
  24. function stop() {
  25. clearTimeout(t);
  26. }
  27. </script>
  28. </head>
  29. <body>
  30. <div id="imageContainer">
  31. <script type="text/javascript">getImage('start')</script>
  32. </div>
  33. <div>
  34. <form name="cameraControlerForm" action="" method="get">
  35. <!-- <input type="button" value="start" onclick="java script:getImage('start');"/> -->
  36. <input type="button" value="stop" onclick="java script:stop();"/>
  37. </form>
  38. </div>
  39. </body>
  40. </html>

i jquery-1.2.6.js

Po pierwsze: zdjęcia codziennie są zapisywane w innym folderze i trzeba by było codziennie o północy zmieniać ścieżkę dostępu w pliku getImage.php. Czy jest możliwość przeszukiwania przez ten skrypt również podfolderów?
Po drugie: kamera robi zdjęcia w rozdzielczości 1280x720 (nie da się tego zmienić) i takie zdjęcia są wyświetlane przez skrypt na stronie. Czy jest możliwość zmiany rozmiaru wyświetlanego przez skrypt obrazu?