Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Pokaz slidow w php z automatycznym importowaniem zdjeć z folderu
Forum PHP.pl > Forum > PHP
DemSka1337
Witam,
Mam ostatnio pewnien problem, ostatnio w szkole dostałem projekt do zrobienia, natomiast konfiguracja raspberrypi w tryb kiosku i zrobienie strony z pokazem automatycznym slajdow z forderu, tzn na pi jest folder (u mnie /var/www/html/images) w którym są zdjęcia i po wklejeniu tam zdjęć to automatycznie zaczynie sie pokaz slajdów ktory jest zapętlony. Nowe zdjęcie jest co ok 3 sekundy.
Znalazłem kod na internecie, ale nie działa, prawdopodobnie przez to że nie umiem skonfigurować lub przez to że jest na php 5 a ja mam php 7. 2 ,ponieważ najnowszy raspbian czyli przerobiony debian 8 (nie pamietam wersji ale ten najnowszy) nie wspiera już php 5.


Screeny:

Strona:
Folder html:
Folder zdjęć:

Kod:
  1. <?
  2. /*
  3. PHP image slideshow - auto version - PHP5
  4. */
  5. // set the absolute path to the directory containing the images
  6. define ('IMGDIR', '/var/www/html/images/');
  7. // same but for www
  8. define ('WEBIMGDIR', '/');
  9. // set session name for slideshow "cookie"
  10. define ('SS_SESSNAME', 'slideshow_sess');
  11. // global error variable
  12. $err = '';
  13. // start img session
  14. session_name(SS_SESSNAME);
  15. // init slideshow class
  16. $ss = new slideshow($err);
  17. if (($err = $ss->init()) != '')
  18. {
  19. header('HTTP/1.1 500 Internal Server Error');
  20. echo $err;
  21. exit();
  22. }
  23. // get image files from directory
  24. $ss->get_images();
  25. // set variables, done.
  26. list($curr, $caption, $first, $prev, $next, $last) = $ss->run();
  27. /*
  28. slideshow class, can be used stand-alone
  29. */
  30. class slideshow
  31. {
  32. private $files_arr = NULL;
  33. private $err = NULL;
  34.  
  35. public function __construct(&$err)
  36. {
  37. $this->files_arr = array();
  38. $this->err = $err;
  39. }
  40. public function init()
  41. {
  42. // run actions only if img array session var is empty
  43. // check if image directory exists
  44. if (!$this->dir_exists())
  45. {
  46. return 'Error retrieving images, missing directory';
  47. }
  48. return '';
  49. }
  50. public function get_images()
  51. {
  52. // run actions only if img array session var is empty
  53. if (isset($_SESSION['imgarr']))
  54. {
  55. $this->files_arr = $_SESSION['imgarr'];
  56. }
  57. else
  58. {
  59. if ($dh = opendir(IMGDIR))
  60. {
  61. while (false !== ($file = readdir($dh)))
  62. {
  63. if (preg_match('/^.*\.(jpg|jpeg|gif|png)$/i', $file))
  64. {
  65. $this->files_arr[] = $file;
  66. }
  67. }
  68. closedir($dh);
  69. }
  70. $_SESSION['imgarr'] = $this->files_arr;
  71. }
  72. }
  73. public function run()
  74. {
  75. $curr = 1;
  76. $last = count($this->files_arr);
  77. if (isset($_GET['img']))
  78. {
  79. if (preg_match('/^[0-9]+$/', $_GET['img'])) $curr = (int) $_GET['img'];
  80. if ($curr <= 0 || $curr > $last) $curr = 1;
  81. }
  82. if ($curr <= 1)
  83. {
  84. $prev = $curr;
  85. $next = $curr + 1;
  86. }
  87. else if ($curr >= $last)
  88. {
  89. $prev = $last - 1;
  90. $next = $last;
  91. }
  92. else
  93. {
  94. $prev = $curr - 1;
  95. $next = $curr + 1;
  96. }
  97. // line below sets the caption name...
  98. $caption = str_replace('-', ' ', $this->files_arr[$curr - 1]);
  99. $caption = str_replace('_', ' ', $caption);
  100. $caption = preg_replace('/\.(jpe?g|gif|png)$/i', '', $caption);
  101. $caption = ucfirst($caption);
  102. return array($this->files_arr[$curr - 1], $caption, 1, $prev, $next, $last);
  103. }
  104. private function dir_exists()
  105. {
  106. return file_exists(IMGDIR);
  107. }
  108.  
  109. }
  110. ?>
  111. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  112. <html xmlns="http://www.w3.org/1999/xhtml">
  113. <head>
  114. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  115. <title>Slideshow</title>
  116. <style type="text/css">
  117. body{margin: 0;padding: 0;font: 100% Verdana, Arial, Helvetica, sans-serif;font-size: 14px;}
  118. div#gallery{border: 1px #ccc solid;width: 600px;margin: 40px auto;text-align: center;}
  119. div#gallery img{margin: 20px;border: 2px #004694 solid;}
  120. div#gallery p{color: #004694;}
  121. div#gallery div.pn{padding: 10px;margin: 0 5px;border-top: 1px #ccc solid;}
  122. a{color:#333;}
  123. a:hover{color:#cc0000;}
  124. a.sp{padding-right: 40px;}
  125. </style>
  126. </head>
  127. <body>
  128. <div id="gallery">
  129. <img src="<?=WEBIMGDIR;?><?=$curr;?>" alt="" />
  130. <p><?=$caption;?></p>
  131. <div class="pn">
  132. <a href="?img=<?=$first;?>">First</a> | <a href="?img=<?=$prev;?>" class="sp">Previous</a><a href="?img=<?=$next;?>">Next</a> | <a href="?img=<?=$last;?>">Last</a>
  133. </div>
  134. </div>
  135. </body>
  136. </html>


Tutaj znalazłem kod: https://www.phpsnaps.com/snaps/view/php-ima...slideshow-auto/
viking
Daj na początku <?php zamiast krótkiej wersji.
DemSka1337
Cytat(viking @ 12.01.2020, 15:25:44 ) *
Daj na początku <?php zamiast krótkiej wersji.


Zrobiłem i to samo prawie...
screen
viking
Ogólnie to ci kodu w ogóle nie parsuje. Próbowałeś najprostsze echo chociaż żeby sprawdzić konfigurację?
DemSka1337
Cytat(viking @ 12.01.2020, 15:36:49 ) *
Ogólnie to ci kodu w ogóle nie parsuje. Próbowałeś najprostsze echo chociaż żeby sprawdzić konfigurację?


Ja taki średni w php i ogólnie html, więc nawet nie wiem co to jest haha.gif
viking
Skoro postawiłeś jakiś serwer na Jeżynce to dobrze by było mieć minimalną wiedzę co ewentualnie dodać zmienić żeby przetestować. Średni w php czy leniwy?
Pyton_000
a masz tam zainstalowany apache + php cochaż? No i nie index.html tylko index.php
DemSka1337
Cytat(viking @ 12.01.2020, 17:01:35 ) *
Skoro postawiłeś jakiś serwer na Jeżynce to dobrze by było mieć minimalną wiedzę co ewentualnie dodać zmienić żeby przetestować. Średni w php czy leniwy?


Dla mnie PHP to czarna magia tak jakby. haha.gif


Cytat(Pyton_000 @ 12.01.2020, 19:59:15 ) *
a masz tam zainstalowany apache + php cochaż? No i nie index.html tylko index.php

Przy index.php to samo . Tak jest apache i PHP
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.