login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Foto gallerijen > fotogallerij met album

fotogallerij met album

Auteur: PeeZz - 25 maart 2006 - 19:23 - Gekeurd door: nemesiskoen - Hits: 18413 - Aantal punten: 2.50 (5 stemmen)



album.php - weergave van de albums in je table
fotos.php - weergave van de fotos van het geselecteerde album
toevoegen.php - fotos toevoegen

bij het voorbeeld heb ik maar één album!

MySQL:

mysql_query("create table foto(
id int not null auto_increment,
primary key(id),
album varchar(100),
naam varchar(200),
bestand varchar(200))")
or die (mysql_error());

changelog:
26-06-2006
Action in toevoegen.php veranderd van index.php?p=fotos/toevoegen naar toevoegen.php n.a.v. dit forumbericht.

Code:
album.php

  1. <table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">
  2. <tr>
  3. <td align="center" height="20" width="75%" style="border-bottom: 1px solid #1ab4e1">fotoalbums</td>
  4. <td align="center" width="15%" style="border-left: 1px solid #1ab4e1; border-bottom: 1px solid #1ab4e1">
  5. <?
  6.  
  7. $maand = array("niet", "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december");
  8.  
  9. $j = date("j");
  10. $n = date("n");
  11. $Y = date("Y");
  12.  
  13. echo $j." ".$maand[$n]." ".$Y;
  14.  
  15. ?>
  16. </td>
  17. </tr>
  18. <tr>
  19. <td colspan="2">
  20. <table cellspacing="0" cellpadding="0" border="0" width="100%">
  21. <tr>
  22. <td width="10" />
  23. <td>
  24. <table cellspacing="0" cellpadding="0" border="0" width="100%">
  25. <tr>
  26. <?
  27. $afbeelding = 0;
  28. $select = "SELECT * FROM foto group by album";
  29. $query = mysql_query($select);
  30. while ($list = mysql_fetch_object($query))
  31. {
  32. if ($afbeelding < 4 ) //4 afb per rij
  33. {
  34. echo '<td width="25%"><a href="index.php?p=fotos/fotos&album='.$list->album.'"><img src="fotos/'.$list->album.'/'.$list->bestand.'"height="75" /></a><br />'.$list->album.'</td>';
  35.  
  36. }
  37. else
  38. {
  39. echo '</tr><tr><td width="25%"><a href="fotos/fotos$album='.$list->album.'"><p><img src="fotos/'.$list->album.'/'.$list->bestand.'" height="75" /></a></td>';
  40. $afbeelding = 0;
  41. }
  42. $afbeelding++;
  43. }
  44. ?>
  45. </tr>
  46. </table>
  47. </td>
  48. </tr>
  49. </table>
  50. </td>
  51. </tr>
  52. </table>



fotos.php

  1. <table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">
  2. <tr>
  3. <td align="center" height="20" width="75%" style="border-bottom: 1px solid #1ab4e1"><? echo $_GET['album']; ?></td>
  4. <td align="center" width="15%" style="border-left: 1px solid #1ab4e1; border-bottom: 1px solid #1ab4e1">
  5. <?
  6.  
  7. $maand = array("niet", "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december");
  8.  
  9. $j = date("j");
  10. $n = date("n");
  11. $Y = date("Y");
  12.  
  13. echo $j." ".$maand[$n]." ".$Y;
  14.  
  15. ?>
  16. </td>
  17. </tr>
  18. <tr>
  19. <td colspan="2">
  20. <table cellspacing="0" cellpadding="0" border="0" width="100%">
  21. <tr>
  22. <td width="10" />
  23. <td>
  24. <table cellspacing="0" cellpadding="0" border="0" width="100%">
  25. <tr>
  26. <?
  27. $album = $_GET['album'];
  28. if(isset($_POST['delf']))
  29. {
  30. $select = "SELECT * FROM foto where album='$album'";
  31. $query = mysql_query($select);
  32. while($dellist = mysql_fetch_object($query))
  33. {
  34. $delid = "del".$dellist->id;
  35. if($_POST[$delid] == 'delete')
  36. {
  37. $bestand = "./fotos/".$dellist->album."/".$dellist->bestand;
  38. unlink($bestand);
  39. $delq = "delete from foto where id=".$dellist->id;
  40. mysql_query($delq);
  41. }
  42. }
  43. }
  44. if(isset($_SESSION['Login']))
  45. {
  46. echo "<form action=\"index.php?p=fotos/fotos&album=".$_GET['album']."\" method=\"post\">";
  47. }
  48. $afbeelding = 0;
  49. $select = "SELECT * FROM foto where album='$album'";
  50. $query = mysql_query($select);
  51. while ($list = mysql_fetch_object($query))
  52. {
  53. if ($afbeelding < 4 ) //4 afb per rij
  54. {
  55. echo '<td width="25%"><a target="_blank" href="fotos/'.$list->album.'/'.$list->bestand.'"><img src="fotos/'.$list->album.'/'.$list->bestand.'"height="75" /></a>';
  56. if(isset($_SESSION['Login']))
  57. {
  58. echo "<input type=\"checkbox\" name=\"del".$list->id."\" value=\"delete\" />";
  59. }
  60. echo '</td>';
  61.  
  62. }
  63. else
  64. {
  65. echo '</tr><tr><td width="25%"><a target="_blank" href="fotos/'.$list->album.'/'.$list->bestand.'"><img src="fotos/'.$list->album.'/'.$list->bestand.'" height="75" /></a>';
  66. if(isset($_SESSION['Login']))
  67. {
  68. echo "<input type=\"checkbox\" name=\"del".$list->id."\" value=\"delete\" />";
  69. }
  70. echo '</td>';
  71. $afbeelding = 0;
  72. }
  73. $afbeelding++;
  74. }
  75. ?>
  76. </tr>
  77. <?
  78. if(isset($_SESSION['Login']))
  79. {
  80. echo '<tr><td><input type="submit" name="delf" value="Fotos verwijderen" /></form></td></tr>';
  81. }
  82. ?>
  83. </table>
  84. </td>
  85. </tr>
  86. </table>
  87. </td>
  88. </tr>
  89. </table>



toevoegen.php

  1. <table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">
  2. <tr>
  3. <td align="center" height="20" width="75%" style="border-bottom: 1px solid #1ab4e1">foto toevoegen</td>
  4. <td align="center" width="15%" style="border-left: 1px solid #1ab4e1; border-bottom: 1px solid #1ab4e1">
  5. <?
  6.  
  7. $maand = array("niet", "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december");
  8.  
  9. $j = date("j");
  10. $n = date("n");
  11. $Y = date("Y");
  12.  
  13. echo $j." ".$maand[$n]." ".$Y;
  14.  
  15. ?>
  16. </td>
  17. </tr>
  18. <tr>
  19. <td colspan="2">
  20. <table cellspacing="0" cellpadding="0" border="0" width="100%">
  21. <tr>
  22. <td width="10"></td>
  23. <td valign="top">
  24. <?
  25. if(isset($_POST['fototoev']))
  26. {
  27. $naam = basename($_FILES['bestand']['name']);
  28. $ext = substr($naam,strlen($naam)-4);
  29.  
  30. if( !strcasecmp($ext, '.jpg') || !strcasecmp($ext, '.gif') )
  31. {
  32. if($_FILES['bestand']['name'] == '' || $_FILES['bestand']['size'] >= '1000000')
  33. {
  34. if($_FILES['bestand']['name'] == '')
  35. {
  36. echo "U hebt geen bestand geselecteerd!";
  37. }
  38. else
  39. {
  40. echo "Het bestand is te groot!";
  41. }
  42. }
  43. else
  44. {
  45. if($_POST['album'] == 1)
  46. {
  47. $album = $_POST['salbum'];
  48. }
  49. else
  50. {
  51. $album = $_POST['nalbum'];
  52. $ndir = "fotos/".$album;
  53. mkdir($ndir,0777);
  54. }
  55.  
  56. $dir = "fotos/".$album."/";
  57. $dir = $dir.$naam;
  58. move_uploaded_file($_FILES['bestand']['tmp_name'],$dir);
  59. $chmod = "./fotos/".$album."/".$naam;
  60. chmod($chmod, 0644);
  61. include("connect.php");
  62.  
  63. $bestand = mysql_escape_string($_FILES['bestand']['name']);
  64. $insert = "insert into foto (naam,album,bestand) values ('$naam','$album','$bestand')";
  65. $query = mysql_query($insert);
  66. echo "De foto werd met succes geupload!";
  67. }
  68. }
  69. else
  70. {
  71. echo "dit is geen afbeelding!";
  72. }
  73. }
  74. else
  75. {
  76. ?>
  77. <form action="toevoegen.php" method="post" enctype="multipart/form-data">
  78. <table cellspacing="0" cellpadding="0" border="0" width="100%">
  79. <tr>
  80. <td>Kies een foto om toe te voegen:</td>
  81. </tr>
  82. <tr>
  83. <td>
  84. <table>
  85. <tr>
  86. <td width="100">bestand:</td>
  87. <td>
  88. <input type="file" name="bestand" />
  89. <input type="submit" name="fototoev" value="Foto toevoegen" />
  90. </td>
  91. <tr>
  92. <td width="100">album:</td><td><input type="radio" checked name="album" value="1" /><select name="salbum"><?
  93. $select = "select album from foto group by album";
  94. $query = mysql_query($select);
  95.  
  96. while($list = mysql_fetch_object($query))
  97. {
  98. echo "<option value=\"".$list->album."\">".$list->album."</option>";
  99. }
  100. ?>
  101. </select>
  102. </td>
  103. </tr>
  104. <tr>
  105. <td /><td><input type="radio" name="album" value="0" /><input type="text" name="nalbum" /></td>
  106. </tr>
  107. </table>
  108. </td>
  109. </tr>
  110. </table>
  111. </form>
  112. <?
  113. }
  114. ?>
  115. </td>
  116. </tr>
  117. </table>
  118. </td>
  119. </tr>
  120. </table>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

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