Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Galeria, jak dodać lokalizacje zdjęć?
Forum PHP.pl > Forum > Przedszkole
GryFF
Znalazłem w necie bardzo fajny skrypt pokazujący zdjęcia tylko jest jeden problem, skrypt pobiera pliki z głownego katalogu a ja chciał bym aby pobierał np z galeria.


o to skrypt



  1. <?
  2. $folder = galeria;
  3. $scale = 0;
  4. $maxwidth = 460;
  5. $maxheight = 500;
  6. $thumbmaxw = 50;
  7. $thumbmaxh = 50;
  8. $imgperpage = 10;
  9. $imgperrow = 5;
  10. $pgperrow = 10;
  11. $currentdir = getcwd ();
  12. $typelist = array("jpg","jpeg","gif","png","JPG");
  13. $imagelist = array();
  14. $title = "Pics";
  15. $stylesheet = '' ;
  16. $home = "{$_SERVER['PHP_SELF']}";
  17. $this_page = "{$_SERVER['PHP_SELF']}";
  18. $caption = "";
  19. $captionext = "txt";
  20.  
  21. //--- ind is put to zero when the script is first called uppon---
  22.  
  23. if(!isset($_GET['ind']))
  24. $_GET['ind'] = 0;
  25. $index = $_GET['ind'];
  26.  
  27. //---the following code iterates through the directory and puts any image found in the imagelist array---
  28.  
  29. $dp=opendir($currentdir);
  30. while ( false != ( $file=readdir($dp) ) ) {
  31. if (is_file($file) && $file!="." && $file!=".."){
  32.  
  33. $extention = explode(".",$file);
  34. $extfield = count($extention)-1;
  35. $extention = $extention[$extfield];
  36.  
  37. if( in_array($extention,$typelist) ){
  38. array_push ($imagelist,$file);
  39. }
  40. }
  41. }
  42. ?>
  43. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  44. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  45.  
  46.  
  47.  
  48.  
  49. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  50. <head>
  51.  
  52.  
  53. <title><?= $title ?></title>
  54. <?
  55. if ($stylesheet == ''){
  56. //--insert the default style sheet into html if none specified
  57. echo '<style type="text/css">'
  58. .'.imag { border-style : solid;'
  59. .'border-color: blue;'
  60. .'border-width : 1px;}'
  61. .'.thumb { border-style : solid;'
  62. .'border-color: #999999;'
  63. .'border-width : 2px;}'
  64. .'A:link { color: #999999;'
  65. .'text-decoration : none; }'
  66. .'A:visited { color: #999999;'
  67. .'text-decoration : none; }'
  68. .'A:hover { color:blue; }'
  69. .'</style>';
  70. } elseif ($stylesheet == 'none') {
  71. //--no style sheet if that is what you want
  72. } else {
  73. echo "<link rel=\"STYLESHEET\" href=\"$stylesheet\" />";
  74. }
  75. ?>
  76. </head>
  77. <body>
  78.  
  79. <table align="center" border="0">
  80. <tr>
  81. <td>
  82. <? if($index-1 >= 0) {?>
  83. <a href='<?= $this_page ?>?ind=<?= $index-1 ?>'>[ prev ]</a>
  84. <? } ?>
  85. </td>
  86. <td>
  87. <?
  88.  
  89. //--- This is where the large pictures are resized so that they maintain ratio---
  90.  
  91. $sizeee = getimagesize ("$imagelist[$index]");
  92. $imgwidth = $sizeee[0];
  93. $imgheight = $sizeee[1];
  94.  
  95. if ($scale == 1 || $imgwidth > $maxwidth || $imgheight > $maxheight) { // decide if img needs to be scaled
  96. $newwidth = $imgwidth/($imgheight/$maxheight);
  97. $newheight = $imgheight/($imgwidth/$maxwidth);
  98. if ($imgwidth < $imgheight) {
  99.  
  100.  
  101.  
  102.  
  103. if ($newwidth > $maxwidth)
  104.  
  105. {
  106.  
  107. ?>
  108. <a href="<?= $imagelist[$index] ?>" target="_blank">
  109. <img src="<?= $imagelist[$index] ?>" width="<?= $maxwidth ?>" height="<?= $newheight ?>" alt="" />
  110. </a>
  111. <?
  112. } else {
  113.  
  114. ?>
  115. <a href="<?= $imagelist[$index] ?>" target="_blank">
  116. <img src="<?= $imagelist[$index] ?>" width="<?= $newwidth ?>" height="<?= $maxheight ?>" alt="" />
  117. </a>
  118. <?
  119. }
  120. } else {
  121.  
  122.  
  123. if ($newhight > $maxheight)
  124.  
  125. {
  126.  
  127. ?>
  128. <a href="<?= $imagelist[$index] ?>" target="_blank">
  129. <img src="<?= $imagelist[$index] ?>" width="<?= $newwidth ?>" height="<?= $maxheight ?>" alt="" />
  130. </a>
  131. <?
  132. } else {
  133.  
  134.  
  135. ?>
  136.  
  137. <a href="<?= $imagelist[$index] ?>" target="_blank">
  138. <img src="<?= $imagelist[$index] ?>" width="<?= $maxwidth ?>" height="<?= $newheight ?>" alt="" />
  139. </a>
  140.  
  141. <?
  142.  
  143.  
  144.  
  145. }
  146. }
  147. } else { ?>
  148. <a href="<?= $imagelist[$index] ?>" target="_blank">
  149. <img src="<?= $imagelist[$index] ?>" width="<?= $imgwidth ?>" height="<?= $imgheight ?>" alt="" />
  150. </a>
  151. <? }
  152. ?>
  153. </td>
  154. <td>
  155. <? if($index+1 < count($imagelist) ) {?>
  156. <a href="<?= $this_page ?>?ind=<?= $index+1 ?>">[ next ]</a>
  157. <? } ?>
  158. </td>
  159. </tr>
  160. <tr>
  161. <td>
  162. </td>
  163. <td>
  164. <center><?
  165. if (file_exists ($imagelist[$index]. "." . $captionext) &&
  166. is_file ($imagelist[$index]. "." . $captionext) &&
  167. !is_dir ($imagelist[$index]. "." . $captionext))
  168. include $imagelist[$index]. "." . $captionext;
  169. else
  170. echo $caption; ?>
  171. </center>
  172. </td>
  173. <td>
  174. </td>
  175. </tr>
  176. </table>
  177.  
  178. <table align="center">
  179. <tr><td></td>
  180. <?
  181.  
  182. //---this code generates the thumbnails based on the configuration settings---
  183.  
  184. $nrpages = ceil( count($imagelist)/$imgperpage );
  185.  
  186. for($j=0;$j<$nrpages;$j++)
  187. {
  188. if( $index >= ($j*$imgperpage) && ($index < (($j+1) * $imgperpage)) ) {
  189. for($i=($j*$imgperpage);$i<(($j+1) * $imgperpage);$i++) {
  190. if(($i%$imgperrow == 0) && ($i > 0)) { ?>
  191. </tr>
  192. <tr>
  193. <? }
  194. if($i <count($imagelist) ) {
  195. $path = "$this_page?ind=".$i; ?>
  196. <td>
  197.  
  198. <?
  199.  
  200.  
  201.  
  202. //--- This is where the thumbnails are resized so that they maintain ratio---
  203.  
  204.  
  205. $sizeee = getimagesize ("$imagelist[$i]");
  206. $imgwidth = $sizeee[0];
  207. $imgheight = $sizeee[1];
  208.  
  209. $newthumbw = $imgwidth/($imgheight/$thumbmaxh);
  210. $newthumbh = $imgheight/($imgwidth/$thumbmaxw);
  211. if ($imgwidth < $imgheight) {
  212.  
  213.  
  214.  
  215.  
  216. if ($newthumbw > $thumbmaxw)
  217.  
  218. {
  219.  
  220. ?>
  221. <a href="<?= $path ?>">
  222. <img src="<?= $imagelist[$i] ?>" width="<?= $thumbmaxw ?>" height="<?= $newthumbh ?>" alt="" />
  223. </a>
  224. <?
  225. } else {
  226.  
  227.  
  228. ?>
  229. <a href="<?= $path ?>">
  230. <img src="<?= $imagelist[$i] ?>" width="<?= $newthumbw ?>" height="<?= $thumbmaxh ?>" alt="" />
  231. </a>
  232. <?
  233. }
  234. } else {
  235.  
  236.  
  237. if ($newthumbh > $thumbmaxh)
  238.  
  239. {
  240.  
  241. ?>
  242. <a href="<?= $path ?>">
  243. <img src="<?= $imagelist[$i] ?>" width="<?= $newthumbw ?>" height="<?= $thumbmaxh ?>" />
  244. </a>
  245. <?
  246. } else {
  247.  
  248.  
  249. ?>
  250.  
  251. <a href="<?= $path ?>">
  252. <img src="<?= $imagelist[$i] ?>" width="<?= $thumbmaxw ?>" height="<?= $newthumbh ?>" alt="" />
  253. </a>
  254.  
  255. <?
  256.  
  257.  
  258.  
  259. }
  260. }
  261. ?>
  262. </td>
  263. <? }
  264. }
  265. }
  266. }
  267. ?>
  268. </tr>
  269. </table>
  270. <br />
  271. <center>
  272. <?
  273. //---this code generates links based on the configuration settings---
  274. //---only puts $pgperrow page links per row to make cleaner---
  275.  
  276. for($j=0;$j<$nrpages;$j++) {
  277. if(($j%$pgperrow == 0) && ($j > 0)) { ?>
  278. <br />
  279. <? } ?>
  280. <a href="<?= $this_page ?>?ind=<?= ($j*$imgperpage) ?>">[page <?= ($j+1) ?>]</a>
  281. <? } ?>
  282. </center>
  283. <center><a href="<?= $home ?>">[ home ]</a></center>
  284. </body>
  285. </html>
  286. </body>
  287. </html>
crocodillo
Ta zmienna zawiera katalog:
  1. $currentdir = getcwd ();


markonix
Próbowałbym z $currentdir.
tolomei
Witaj.

Zmień linijkę 11. na odpowiadającą Twoim zasobom bezpośrednią cieżkę. Np.:
  1. $currentdir = '/sciezka/do/plikow/graficznych';


Pozdrawiam.
GryFF
@tolomei niestety nie działa tzn, zdjęcia w katalogu są a nic nie wyświetla..
tolomei
Napisz mi jaką ścieżkę masz do skryptu a jaką do obrazków.
GryFF
obrazy

www.ospnadolany.cba.pl/galeria.php


a do zdjęć chcę mieć

www.ospnadolany.cba.pl/zdjecia/
lukasz_os
No to wpisz :

  1. $currentdir = '/zdjecia';
tolomei
Dodatkowo:
Linie 30. oraz 31. zmień na:
  1. while ( false !== ( $file=readdir($dp) ) ) {
  2. if (is_file($currentdir.DIRECTORY_SEPARATOR.$file) && $file!="." && $file!=".."){


Linię 38. zmień na:
  1. array_push ($imagelist,$currentdir.DIRECTORY_SEPARATOR.$file);
GryFF
nie działa..


może ktoś przerobić ten kod i dać go całego?
tolomei
To już na pewno zadziała.

  1. <?
  2. $folder = galeria;
  3. $scale = 0;
  4. $maxwidth = 460;
  5. $maxheight = 500;
  6. $thumbmaxw = 50;
  7. $thumbmaxh = 50;
  8. $imgperpage = 10;
  9. $imgperrow = 5;
  10. $pgperrow = 10;
  11. $cursign = './';
  12. $currentdir = 'zdjecia';
  13. $typelist = array("jpg","jpeg","gif","png","JPG");
  14. $imagelist = array();
  15. $title = "Pics";
  16. $stylesheet = '' ;
  17. $home = "{$_SERVER['PHP_SELF']}";
  18. $this_page = "{$_SERVER['PHP_SELF']}";
  19. $caption = "";
  20. $captionext = "txt";
  21.  
  22. //--- ind is put to zero when the script is first called uppon---
  23.  
  24. if(!isset($_GET['ind']))
  25. $_GET['ind'] = 0;
  26. $index = $_GET['ind'];
  27.  
  28. //---the following code iterates through the directory and puts any image found in the imagelist array---
  29.  
  30. $dp=opendir($cursign.$currentdir);
  31. while ( false !== ( $file=readdir($dp) ) ) {
  32. if (is_file($cursign.$currentdir.DIRECTORY_SEPARATOR.$file) && $file!="." && $file!=".."){
  33.  
  34. $extention = explode(".",$file);
  35. $extfield = count($extention)-1;
  36. $extention = $extention[$extfield];
  37.  
  38. if( in_array($extention,$typelist) ){
  39. array_push ($imagelist,$currentdir.DIRECTORY_SEPARATOR.$file);
  40. }
  41. }
  42. }
  43. ?>
  44. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  45. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  46.  
  47.  
  48.  
  49.  
  50. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  51. <head>
  52.  
  53.  
  54. <title><?= $title ?></title>
  55. <?
  56. if ($stylesheet == ''){
  57. //--insert the default style sheet into html if none specified
  58. echo '<style type="text/css">'
  59. .'.imag { border-style : solid;'
  60. .'border-color: blue;'
  61. .'border-width : 1px;}'
  62. .'.thumb { border-style : solid;'
  63. .'border-color: #999999;'
  64. .'border-width : 2px;}'
  65. .'A:link { color: #999999;'
  66. .'text-decoration : none; }'
  67. .'A:visited { color: #999999;'
  68. .'text-decoration : none; }'
  69. .'A:hover { color:blue; }'
  70. .'</style>';
  71. } elseif ($stylesheet == 'none') {
  72. //--no style sheet if that is what you want
  73. } else {
  74. echo "<link rel=\"STYLESHEET\" href=\"$stylesheet\" />";
  75. }
  76. ?>
  77. </head>
  78. <body>
  79.  
  80. <table align="center" border="0">
  81. <tr>
  82. <td>
  83. <? if($index-1 >= 0) {?>
  84. <a href='<?= $this_page ?>?ind=<?= $index-1 ?>'>[ prev ]</a>
  85. <? } ?>
  86. </td>
  87. <td>
  88. <?
  89.  
  90. //--- This is where the large pictures are resized so that they maintain ratio---
  91.  
  92. $sizeee = getimagesize ("$imagelist[$index]");
  93. $imgwidth = $sizeee[0];
  94. $imgheight = $sizeee[1];
  95.  
  96. if ($scale == 1 || $imgwidth > $maxwidth || $imgheight > $maxheight) { // decide if img needs to be scaled
  97. $newwidth = $imgwidth/($imgheight/$maxheight);
  98. $newheight = $imgheight/($imgwidth/$maxwidth);
  99. if ($imgwidth < $imgheight) {
  100.  
  101.  
  102.  
  103.  
  104. if ($newwidth > $maxwidth)
  105.  
  106. {
  107.  
  108. ?>
  109. <a href="<?= $imagelist[$index] ?>" target="_blank">
  110. <img src="<?= $imagelist[$index] ?>" width="<?= $maxwidth ?>" height="<?= $newheight ?>" alt="" />
  111. </a>
  112. <?
  113. } else {
  114.  
  115. ?>
  116. <a href="<?= $imagelist[$index] ?>" target="_blank">
  117. <img src="<?= $imagelist[$index] ?>" width="<?= $newwidth ?>" height="<?= $maxheight ?>" alt="" />
  118. </a>
  119. <?
  120. }
  121. } else {
  122.  
  123.  
  124. if ($newhight > $maxheight)
  125.  
  126. {
  127.  
  128. ?>
  129. <a href="<?= $imagelist[$index] ?>" target="_blank">
  130. <img src="<?= $imagelist[$index] ?>" width="<?= $newwidth ?>" height="<?= $maxheight ?>" alt="" />
  131. </a>
  132. <?
  133. } else {
  134.  
  135.  
  136. ?>
  137.  
  138. <a href="<?= $imagelist[$index] ?>" target="_blank">
  139. <img src="<?= $imagelist[$index] ?>" width="<?= $maxwidth ?>" height="<?= $newheight ?>" alt="" />
  140. </a>
  141.  
  142. <?
  143.  
  144.  
  145.  
  146. }
  147. }
  148. } else { ?>
  149. <a href="<?= $imagelist[$index] ?>" target="_blank">
  150. <img src="<?= $imagelist[$index] ?>" width="<?= $imgwidth ?>" height="<?= $imgheight ?>" alt="" />
  151. </a>
  152. <? }
  153. ?>
  154. </td>
  155. <td>
  156. <? if($index+1 < count($imagelist) ) {?>
  157. <a href="<?= $this_page ?>?ind=<?= $index+1 ?>">[ next ]</a>
  158. <? } ?>
  159. </td>
  160. </tr>
  161. <tr>
  162. <td>
  163. </td>
  164. <td>
  165. <center><?
  166. if (file_exists ($imagelist[$index]. "." . $captionext) &&
  167. is_file ($imagelist[$index]. "." . $captionext) &&
  168. !is_dir ($imagelist[$index]. "." . $captionext))
  169. include $imagelist[$index]. "." . $captionext;
  170. else
  171. echo $caption; ?>
  172. </center>
  173. </td>
  174. <td>
  175. </td>
  176. </tr>
  177. </table>
  178.  
  179. <table align="center">
  180. <tr><td></td>
  181. <?
  182.  
  183. //---this code generates the thumbnails based on the configuration settings---
  184.  
  185. $nrpages = ceil( count($imagelist)/$imgperpage );
  186.  
  187. for($j=0;$j<$nrpages;$j++)
  188. {
  189. if( $index >= ($j*$imgperpage) && ($index < (($j+1) * $imgperpage)) ) {
  190. for($i=($j*$imgperpage);$i<(($j+1) * $imgperpage);$i++) {
  191. if(($i%$imgperrow == 0) && ($i > 0)) { ?>
  192. </tr>
  193. <tr>
  194. <? }
  195. if($i <count($imagelist) ) {
  196. $path = "$this_page?ind=".$i; ?>
  197. <td>
  198.  
  199. <?
  200.  
  201.  
  202.  
  203. //--- This is where the thumbnails are resized so that they maintain ratio---
  204.  
  205.  
  206. $sizeee = getimagesize ("$imagelist[$i]");
  207. $imgwidth = $sizeee[0];
  208. $imgheight = $sizeee[1];
  209.  
  210. $newthumbw = $imgwidth/($imgheight/$thumbmaxh);
  211. $newthumbh = $imgheight/($imgwidth/$thumbmaxw);
  212. if ($imgwidth < $imgheight) {
  213.  
  214.  
  215.  
  216.  
  217. if ($newthumbw > $thumbmaxw)
  218.  
  219. {
  220.  
  221. ?>
  222. <a href="<?= $path ?>">
  223. <img src="<?= $imagelist[$i] ?>" width="<?= $thumbmaxw ?>" height="<?= $newthumbh ?>" alt="" />
  224. </a>
  225. <?
  226. } else {
  227.  
  228.  
  229. ?>
  230. <a href="<?= $path ?>">
  231. <img src="<?= $imagelist[$i] ?>" width="<?= $newthumbw ?>" height="<?= $thumbmaxh ?>" alt="" />
  232. </a>
  233. <?
  234. }
  235. } else {
  236.  
  237.  
  238. if ($newthumbh > $thumbmaxh)
  239.  
  240. {
  241.  
  242. ?>
  243. <a href="<?= $path ?>">
  244. <img src="<?= $imagelist[$i] ?>" width="<?= $newthumbw ?>" height="<?= $thumbmaxh ?>" />
  245. </a>
  246. <?
  247. } else {
  248.  
  249.  
  250. ?>
  251.  
  252. <a href="<?= $path ?>">
  253. <img src="<?= $imagelist[$i] ?>" width="<?= $thumbmaxw ?>" height="<?= $newthumbh ?>" alt="" />
  254. </a>
  255.  
  256. <?
  257.  
  258.  
  259.  
  260. }
  261. }
  262. ?>
  263. </td>
  264. <? }
  265. }
  266. }
  267. }
  268. ?>
  269. </tr>
  270. </table>
  271. <br />
  272. <center>
  273. <?
  274. //---this code generates links based on the configuration settings---
  275. //---only puts $pgperrow page links per row to make cleaner---
  276.  
  277. for($j=0;$j<$nrpages;$j++) {
  278. if(($j%$pgperrow == 0) && ($j > 0)) { ?>
  279. <br />
  280. <? } ?>
  281. <a href="<?= $this_page ?>?ind=<?= ($j*$imgperpage) ?>">[page <?= ($j+1) ?>]</a>
  282. <? } ?>
  283. </center>
  284. <center><a href="<?= $home ?>">[ home ]</a></center>
  285. </body>
  286. </html>
  287. </body>
  288. </html>
GryFF
no lol nie dziala ohmy.gif


proszę zobaczyć

http://ospnadolany.cba.pl/galeria.php
xxdrago
Sprawdź, co zawiera: samo $dp bez opendir. i wklej tutaj... smile.gif
GryFF
wyjaśnij lepiej o co ci chodzi.
xxdrago
i powinieneś wiedzieć o co chodzi smile.gif
  1. echo $cursign.$currentdir;


przed:
  1. $dp=opendir($cursign.$currentdir);
GryFF
Teraz w miejsce gdzie powinna być galeria jest to "./zdjecia "

http://ospnadolany.cba.pl/galeria.php
xxdrago
  1. $cursign = './';

zmien na:
  1. $cursign = '';


  1. $currentdir = 'zdjecia';


to zamień na:
  1. $currentdir = '/zdjecia/';


i usuń to echo co wcześniej ci dalem.
GryFF
  1. $currentdir = 'zdjecia';


to tak powinno być ;-)

działa, dla was +
xxdrago
Tak, własnie myślałem, ale na przyszłość staraj się takie problemy rozwiązywać sam, nie są one bardzo ciężkie.


Pozdrawiam
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-2025 Invision Power Services, Inc.