Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Pokaz slidow w php z automatycznym importowaniem zdjeć z folderu
DemSka1337
post 12.01.2020, 15:19:23
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 12.01.2020

Ostrzeżenie: (0%)
-----


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/

Ten post edytował DemSka1337 12.01.2020, 15:20:58
Go to the top of the page
+Quote Post
viking
post 12.01.2020, 15:25:44
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Daj na początku <?php zamiast krótkiej wersji.


--------------------
Go to the top of the page
+Quote Post
DemSka1337
post 12.01.2020, 15:32:38
Post #3





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 12.01.2020

Ostrzeżenie: (0%)
-----


Cytat(viking @ 12.01.2020, 15:25:44 ) *
Daj na początku <?php zamiast krótkiej wersji.


Zrobiłem i to samo prawie...
screen
Go to the top of the page
+Quote Post
viking
post 12.01.2020, 15:36:49
Post #4





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Ogólnie to ci kodu w ogóle nie parsuje. Próbowałeś najprostsze echo chociaż żeby sprawdzić konfigurację?


--------------------
Go to the top of the page
+Quote Post
DemSka1337
post 12.01.2020, 16:13:41
Post #5





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 12.01.2020

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post
viking
post 12.01.2020, 17:01:35
Post #6





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


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?


--------------------
Go to the top of the page
+Quote Post
Pyton_000
post 12.01.2020, 19:59:15
Post #7





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


a masz tam zainstalowany apache + php cochaż? No i nie index.html tylko index.php
Go to the top of the page
+Quote Post
DemSka1337
post 13.01.2020, 08:05:21
Post #8





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 12.01.2020

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 12:42