login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Foto gallerijen > Foto Album

Foto Album

Auteur: webbiexl - 31 augustus 2004 - 19:47 - Gekeurd door: Dennisvb - Hits: 57391 - Aantal punten: 3.98 (24 stemmen)




Dit is een perfect foto album dat ik flink verbeterd heb. Het origineel is van Ward Roeffen, dat je het ff weet.

Functies van het Album.
Het album bestaat uit 2 delen.
- album.php
- albumlist.php

- albumlist.php
Dit is de pagina die je include op je indexpagina. Ward had op zijn homepage een soort gelijk iets staan alleen had hij dit niet bij zijn script gezet. Dus ik heb dit nagemaakt, omdat hij een overzichtelijke pagina in elkaar had gezet en daar nix mis mee was.
Deze pagina verwijst naar de verschillende albums (mappen), en komt vervolgens uit op album.php waarover ik het volgende uit te leggen heb.

- album.php
In het album van ward zaten een paar kleine dingen die eruit of er juist in moesten.
Zo ontbrak er een database connectie en moest je special thumbnails aanmaken. Dit heb ik onderandere veranderd zodat het script completer wordt.

album.php werkt heel simpel.
Je moet je map met foto's uploaden naar je server. Deze map is direct al het album.
Het enige wat je moet doen om die op te roepen is de link te veranderen in albumlist.php.

Dit gaat als volgt

  1. <a href="?page=album&boek=album1">Foto's bekijken</a>


Verander in de link hier boven 'album1' in de naam van je map. Wil je bijvoorbeeld
'mijn verjaardag' als naam hebben noem dan de map 'mijn_verjaardag'. Het script zet _ automatisch om in spaties

album.php verwerkt, dankzij veranderingen, alle foto's in de geplaatste mappen tot thumbnails. Deze thumbnails dienen als link om naar de foto zelf te gaan.
Ook kan je onder elke foto reacties plaatsen, maar dan moet je wel eerst even deze tabel aanmaken.

  1. CREATE TABLE fotosreacties (
  2. id int(11) NOT NULL auto_increment,
  3. boek varchar(60) NOT NULL default '',
  4. foto varchar(60) NOT NULL default '',
  5. naam varchar(30) NOT NULL default '',
  6. datum int(11) NOT NULL default '0',
  7. reactie text NOT NULL,
  8. PRIMARY KEY (id)
  9. ) TYPE=MyISAM;


Ik hoop dat jullie er gebruik van zullen maken en laat ff weten wat je er van vindt!

grtz Webbie XL

Code:
albumlist.php

  1. <html>
  2.  
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  5. <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
  6. <meta name="ProgId" content="FrontPage.Editor.Document">
  7. <title>Foto Album</title>
  8. </head>
  9.  
  10. <body>Foto's<br>
  11. <table cellspacing="0" border="0" cellpadding="0" width="90%">
  12. <tr><td colspan="2"><hr></td></tr>
  13. <tr>
  14. <td rowspan="2" align="center" width="200"><a href="album.php?page=album&boek=album1"><img src="" height="100" alt="Album 1" border="0"></a></td>
  15. <td valign="top"><font face="Arial" size="2">Album 1<br>
  16. </font><font face="Arial" size="1">Foto's van bijvoorbeeld je schoonmoeder.</font><br>
  17. </td>
  18. </tr>
  19. <tr>
  20. <td valign="bottom"><a href="album.php?page=album&boek=album1">Foto's bekijken</a></td>
  21. </tr>
  22. <tr><td colspan="2"><hr></td></tr>
  23. <tr>
  24. <td rowspan="2" align="center" width="200"><a href="album.php?page=album&boek=album2"><img src="" height="100" alt="Album 2" border="0"></a></td>
  25. <td valign="top"><font face="Arial" size="2">Album 2<br>
  26. </font><font face="Arial" size="1">Foto's van bijvoorbeeld je zomervakantie.</font><br>
  27. </td>
  28. </tr>
  29. <tr>
  30. <td valign="bottom"><a href="album.php?page=album&boek=album2">Foto's bekijken</a></td>
  31. </tr>
  32. <tr><td colspan="2"><hr></td></tr>
  33.  
  34.  
  35. </table>
  36.  
  37.  
  38. </body>
  39.  
  40. </html>


album.php

  1. <?
  2.  
  3. $host="localhost";
  4. $user="naam";
  5. $password="w8woord";
  6. $dbnaam="DBnaam";
  7. $db=mysql_connect($host,$user,$password) or die(mysql_error());
  8. mysql_select_db($dbnaam,$db) or die("mysql_errno():mysql_error()");
  9.  
  10. if(is_dir($_GET['boek'])){
  11. // configuratie
  12. $aantalFotos = 18; // aantal fotos per pagina
  13. $originalPath = $_GET['boek']; //de map aangeroepen in de url
  14. $path = $_GET['boek']; // path naar de foto
  15.  
  16. $fotoArray = array();
  17.  
  18. $d = dir("$path");
  19.  
  20. while($entry=$d->read()) {
  21. if(eregi(".jpg|.jpeg|.gif|.bmp|.png", $entry)){
  22.  
  23. $foto = $path . "/" . $entry ;
  24. $fotoArray[] = $foto;
  25.  
  26. }
  27.  
  28. }
  29.  
  30. $d->close();
  31. $count = count($fotoArray);
  32.  
  33. $pathspatie = str_replace("_", "&nbsp;", $originalPath);
  34.  
  35.  
  36. // reactie Plaatsen
  37. if(isset($_POST["submitreactie"])){
  38. $query = "insert into fotosreacties (boek,foto,naam,datum,reactie) values ";
  39. $query .= "('" . $_GET['boek'] . "','" . $fotoArray[$_GET["fotoID"]] . "','" . $_POST["naam"] . "','" . time() . "','" . $_POST["reactie"] . "')";
  40.  
  41. if($result = mysql_query($query)){
  42. echo "Je reactie is geplaatst";
  43. } // end if
  44. else {
  45. echo "Sorry, je reactie kon niet geplaatst worden.";
  46. } // end else
  47.  
  48. } // end if
  49.  
  50.  
  51.  
  52. // kijken hoeveel reacties iedere foto heeft
  53. $reacties;
  54. $query = "select foto from fotosreacties where boek = '" . $_GET['boek'] . "'";
  55. if($result = mysql_query($query)){
  56. while ($r = mysql_fetch_array($result)){
  57. while ($foto = current($fotoArray)) {
  58. if ($foto==$r["foto"]){
  59. $key = key($fotoArray);
  60. } // end if
  61. next($fotoArray);
  62. } // end while
  63. if(!isset($reacties[$key])){
  64. $reacties[$key] = 1;
  65. } // end if
  66. else {
  67. $reacties[$key]++;
  68. } // end else
  69. reset($fotoArray);
  70.  
  71. } // end while
  72. } // end if
  73. ?>
  74.  
  75. <html>
  76. <head>
  77. <title>Fotos</title>
  78. </head>
  79.  
  80. <body>
  81.  
  82.  
  83. <table width="100%"><tr><td align="center" width="100%">
  84.  
  85. <?
  86.  
  87.  
  88. // 1 FOTO PER PAGINA
  89.  
  90. if((isset($_GET['fotoID'])) AND (intval($_GET['fotoID']>=0)) AND (intval($_GET['fotoID'] < $count))){
  91. $showFoto = intval($_GET['fotoID']);
  92.  
  93. echo "<table width='40%'><tr><td colspan='3' align='center'><b>" . $pathspatie . "</b>
  94. <br><br><small>Foto " . ($showFoto + 1) . " / " . $count . "</small></big></font> </td></tr><tr>";
  95.  
  96. echo "<tr><td colspan='3' align='center'><a href='" . $fotoArray[$showFoto] . "' target='_blanc'><img src='" . $fotoArray[$showFoto] . "' height='300' border='0'></a></td></tr>";
  97. echo "<tr><td width='40%'>";
  98. if($showFoto!=0){
  99. $prevFoto = ($showFoto - 1);
  100. echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=album&boek=" . $originalPath . "&fotoID=" . $prevFoto . "'>prev</a> ";
  101. } // end if
  102. echo "</td><td width='33%'>";
  103. $pageNR = floor($_GET['fotoID'] / $aantalFotos);
  104. $pageNR = $pageNR * 18;
  105. echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=album&boek=" . $originalPath . "&vanafFoto=" . $pageNR . "'>list</a> ";
  106. echo "</td><td align='right'>";
  107. if($showFoto!=($count -1)){
  108. $nextFoto = ($showFoto + 1);
  109. echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=album&boek=" . $originalPath . "&fotoID=" . $nextFoto . "'>next</a> ";
  110. } // end if
  111. echo "</td></tr></table>";
  112.  
  113.  
  114. echo "<br><br><b>Reacties</b>";
  115.  
  116. $reacties;
  117. $query = "SELECT * FROM fotosreacties where foto = '" . $fotoArray[$showFoto] . "' order by datum ASC";
  118. if($result = mysql_query($query)){
  119. if(mysql_numrows($result)==0){
  120. echo "<br><br>Er zijn nog geen reacties";
  121. } // end if
  122. else {
  123. echo "<table width='40%' cellspacing='0' border='0' cellpadding='0'>";
  124. echo "<tr><td colspan='2'><hr></td></tr>";
  125. while ($r = mysql_fetch_array($result)){
  126. echo "<tr><td><b>" . $r["naam"] . "</b> ";
  127. echo "</td><td width='40%'><small>[ " . date("d/m/Y @ H:i",$r["datum"]) . " ]</small></td><tr>";
  128. echo "<tr><td colspan='2'>" . $r["reactie"] . "</td></tr>";
  129. echo "<tr><td colspan='2'><hr></td></tr>";
  130. } // end while
  131. echo "</table>";
  132. } // end else
  133. } // end if
  134.  
  135. echo "<form method='post' action=''>";
  136. echo "<table>";
  137. echo "<tr>";
  138. echo "<td>Naam:<br><input type='text' name='naam'></td></tr>";
  139. echo "<tr><td>Jouw Reactie:<br><textarea name='reactie' cols='30' rows='5'></textarea><br></td></tr>";
  140. echo "<tr><td><input type='submit' name='submitreactie' value='Verzenden'></td></tr>";
  141. echo "</table>";
  142. echo "</form>";
  143.  
  144.  
  145.  
  146. } // end if
  147.  
  148. // X FOTOS PER PAGINA
  149.  
  150. else {
  151.  
  152. // configuratie
  153. $clm = "3"; // Aantal kolommen
  154.  
  155.  
  156. $countFotos = count($fotoArray);
  157. $thumbPath = $path . "/"; //Path naar thumps
  158. $path2 = $path . "/";
  159.  
  160.  
  161.  
  162. echo "<br><table ><tr>";
  163.  
  164. echo "<td align='center' colspan='" . $clm . "'>";
  165.  
  166.  
  167. // navigatie
  168. $navigation;
  169. if($countFotos < ($aantalFotos + 1)){
  170. $begin = 0;
  171. $eind = $countFotos;
  172.  
  173. } // end if
  174. else {
  175.  
  176. $aantalPages = ceil($countFotos / $aantalFotos) ;
  177. for($i=1; $i < $aantalPages + 1; $i++){
  178. $pageNR = ($i - 1) * $aantalFotos;
  179.  
  180. if($pageNR==$_GET["vanafFoto"]){
  181. $navigation .= "<small><font color='#990000'>" . $i . "</font></small> ";
  182. }
  183. else {
  184. $navigation .= "<a href='?page=album&boek=" . $originalPath . "&vanafFoto=" . $pageNR . "'>" . $i . "</a> ";
  185. }
  186. } // end for
  187.  
  188.  
  189. if((isset($_GET['vanafFoto'])) AND (intval($_GET['vanafFoto']>=0)) AND (intval($_GET['vanafFoto'] < $countFotos))){
  190. $begin = intval($_GET['vanafFoto']);
  191.  
  192. if(($begin + $aantalFotos) <= $countFotos){
  193. $eind = ($begin + $aantalFotos);
  194. } // end if
  195. else {
  196. $eind = $countFotos;
  197. } // end else
  198.  
  199. } // end if
  200. else {
  201. $begin = 0;
  202. $eind = $aantalFotos;
  203. } // end else
  204.  
  205. $countFotos = count($fotoArray);
  206.  
  207.  
  208. // path naar echte foto
  209.  
  210. } // end else
  211.  
  212. echo "<table border='0' cellpadding='0' cellspacing='2'><tr><td ><b>" . $pathspatie . "</b> <small>(" . $count . ")</small>
  213. <br><br><center><small>Pictures " . ($begin + 1) . " - " . $eind . "</small></center></td></tr></table>";
  214.  
  215.  
  216.  
  217. if(($begin - $aantalFotos) >= 0){
  218. $navigation = "<a href='" . $_SERVER['PHP_SELF'] . "?page=album&boek=" . $originalPath . "&vanafFoto=" . ($begin - $aantalFotos) . "'><</a> " . $navigation;
  219. } // end if
  220.  
  221.  
  222. if(($begin + $aantalFotos) < $count){
  223. $navigation .= " <a href='" . $_SERVER['PHP_SELF'] . "?page=album&boek=" . $originalPath . "&vanafFoto=" . ($begin + $aantalFotos) . "'>></a>";
  224. } // end if
  225.  
  226. echo $navigation . "<br><br>";
  227. echo "</td></tr><tr>";
  228. $fotonr = 1;
  229. for($i=$begin; $i < $eind; $i++){
  230.  
  231.  
  232. $thumb = str_replace($path2, $thumbPath, $fotoArray[$i]);
  233.  
  234.  
  235. echo "<td align='center'><a href='" . $_SERVER['PHP_SELF'] . "?page=album&boek=" . $originalPath . "&fotoID=" . $i . "'><img border='0' src='" . $thumb . "' height='100'><br>";
  236. echo "<small>reacties (";
  237. if($reacties[$i]==0){
  238. echo "0";
  239. } // end if
  240. else {
  241. echo $reacties[$i];
  242. } // end else
  243. echo ")</small>";
  244. echo "</a></td>";
  245. $fotonr++;
  246. if($fotonr == ($clm + 1)){
  247. echo "</tr>\n<tr>";
  248. $fotonr = 1;
  249. } // end if
  250.  
  251.  
  252.  
  253.  
  254. } // end for
  255. echo "</tr>";
  256.  
  257. echo "<td align='center' colspan='" . $clm . "'>";
  258.  
  259. echo $navigation;
  260.  
  261. echo "</td></tr><tr>";
  262.  
  263. echo "</table>";
  264.  
  265.  
  266. } // end else if
  267. } // end if
  268. else {
  269. echo "Dit fotoalbum bestaat niet";
  270. } // end else
  271.  
  272.  
  273.  
  274. ?>
  275. </td></tr></table>
  276.  
  277.  
  278.  
  279. </body>
  280. </html>
Download code! Download code (.txt)

 Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (56)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.079s