login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Foto toevoegen aan nieuwssysteem

Offline yncklytn - 25/06/2012 12:21
Avatar van yncklytnLid Hallo,

Ik ben nog niet zolang bezig met php, Ik ben bezig met het maken van een nieuwssysteem waar ook foto's bij toegevoegd kunnen worden. Ik ben al redelijk ver, maar het deel om foto's toe te voegen lukt me nog niet. Het lukt me al om een foto te uploaden en op te slaan in de databank, maar als ik op deze foto klik zou er normaal een stukje code van de foto in het tekstvak moeten komen om een nieuwsbericht toe te voegen/bewerken. Ziet iemand waar ik ergens fout zit?

Alvast Bedankt!

  1. <?php
  2.  
  3. //ini_set('display_errors', 1); // 0 = uit, 1 = aan
  4. //error_reporting(E_ALL);
  5.  
  6. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  7.  
  8. if ($_POST['voegtoe']) {
  9. $photoFileName = $_FILES['photo']['name']; // get client side file name
  10. if ($photoFileName) { // file uploaded
  11. $fileNameParts = explode(".", $photoFileName);
  12. $fileExtension = end($fileNameParts); // part behind last dot
  13.  
  14. if ($fileExtension != "jpg" && $fileExtension != "JPEG" && $fileExtension != "JPG") {
  15. die ("Kies aub een <b>jpg</b> foto, ga terug en probeer het opnieuw.");
  16. }
  17.  
  18. $photoSize = $_FILES['photo']['size']; // size of uploaded file
  19. if ($photoSize == 0) {
  20. die ("Kies eerst een foto en klik daarna pas op \"voegtoe\", ga terug en probeer het opnieuw.");
  21. }
  22.  
  23. // read photo
  24. $tempFileName = $_FILES['photo']['tmp_name']; // temporary file at server side
  25. $src_img = imagecreatefromjpeg ($tempFileName);
  26.  
  27. $width = imagesx($src_img); // get original source image width
  28. $height = imagesy($src_img); // and height
  29.  
  30. // create small thumbnail
  31. if (($height * 3) / 4 > $width) {
  32. $dest_height = 260;
  33. $dest_width = (260 * $width) / $height;
  34. } else {
  35. $dest_width = 200;
  36. $dest_height = (200 * $height) / $width;
  37. }
  38.  
  39. $dest_img = imagecreatetruecolor($dest_width, $dest_height);
  40.  
  41. $result = imagecopyresampled($dest_img, $src_img,0, 0, 0, 0, $dest_width, $dest_height,$width, $height); // resize the image
  42.  
  43. $indexke = strrpos($photoFileName, '.');
  44. $photoFileName = substr ($photoFileName, 0, $indexke) . ".png";
  45.  
  46. imagepng($dest_img, "fotos_groot/thumbs/" . $photoFileName); // save image
  47. imagepng($src_img, "fotos_groot/fotos/" . $photoFileName);
  48.  
  49. imagedestroy($src_img);
  50. imagedestroy($dest_img);
  51.  
  52. mysql_query("INSERT INTO nieuws_fotos_groot (naam, height, width, height_groot, width_groot)
  53. values ('$photoFileName', '$dest_height', '$dest_width', '$height', '$width')") or die ("fout bij het vastleggen van de foto in de databank");
  54. }
  55. }
  56.  
  57. }
  58.  
  59. if (isset($id)) {
  60.  
  61. $result = mysql_query("SELECT *
  62. FROM nieuws_fotos_groot
  63. WHERE id = '$id'");
  64. $show_msg = mysql_fetch_array($result);
  65.  
  66. echo ( "<script language=\"javascript\" type=\"text/javascript\">\n<!--\n" .
  67. "opener.document.submitform.boodschap.value += \" [foto $show_msg[naam] width=$show_msg[width] height=$show_msg[height]]" . $id . "[/foto]\";\n" .
  68. "window.close();\n" .
  69. "// -->\n</script>\n");
  70. // else show the form to submit new data:
  71. }
  72. else
  73. {
  74. ?>
  75.  
  76. <script language="javascript" type="text/javascript">
  77. <!--
  78. function hidebuttons(theform) {
  79. document.body.style.cursor = "wait";
  80. //if IE 4+ or NS 6+
  81. if (document.all||document.getElementById) {
  82. //screen thru every element in the form, and hunt down "submit" and "reset"
  83. for (i=0;i<theform.length;i++) {
  84. var tempobj=theform.elements[i]
  85. try {
  86. if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") {
  87. tempobj.style.display='none';
  88. theform.elements[tempobj.name + "_hidden"].style.display="inline";
  89. }
  90. }
  91. catch(errorObject) {}
  92. }
  93. }
  94. }
  95. // --->
  96. <div align="center">
  97. <table border="0" width="95%" cellspacing="0" cellpadding="0">
  98. <tr>
  99. <td class="tekst">
  100. <br>
  101. <div class="titel">Selecteer een foto</div>
  102. </td>
  103. </tr>
  104. <tr>
  105. <td bgcolor="#c0c0c0">
  106. <img src="images/niks.gif" height="1" width="1" alt="">
  107. </td>
  108. </tr>
  109. <tr>
  110. <td class="tekst">
  111. <div align="center">
  112. <table border="0" cellspacing="15">
  113. <tr>
  114.  
  115. <?php
  116. $teller = 1;
  117.  
  118. $results = mysql_query("SELECT *
  119. FROM nieuws_fotos_groot
  120. WHERE id != '0'");
  121. while($show_msg = mysql_fetch_array($results))
  122. {
  123. echo("<td align=\"center\"><table border=\"0\" cellspacing=\"2\" cellpadding=\"0\" bgcolor=\"#c0c0c0\"><tr><td><a href=\"foto_groot.php?id=$show_msg[id]&naam=$show_msg[naam]\"><img src=\"fotos_groot/thumbs/$show_msg[naam]\" width=\"$show_msg[width]\" height=\"$show_msg[height]\" border=\"0\" alt=\"klik om te selecteren\"></a></td></tr></table></td>\n");
  124. if ($teller++ % 2 == 0)
  125. echo ("</tr><tr>\n");
  126. }
  127. ?>
  128. </table>
  129. <br>
  130.  
  131. <form onsubmit="hidebuttons(this)" method="post" action="<?php $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
  132. <table border="0" bgcolor="#cccccc" cellspacing="1" cellpadding="0" width="95%">
  133. <tr>
  134. <td>
  135. <table border="0" cellspacing="5" width="100%" bgcolor="#f6f6f6">
  136. <tr>
  137. <td>
  138. <table border="0" cellspacing="5" width="100%">
  139. <tr>
  140. <td class="tekst" valign="top" colspan="3"><font size="-2">foto toevoegen<br><br></font>
  141. </td>
  142. </tr>
  143. <tr>
  144. <td class="tekst" valign="top"><b>Selecteer foto</b>
  145. </td>
  146. <td><input type="file" name="photo" class="formke" size="25" accept="image/jpeg"><br><br>
  147. </td>
  148. <td class="tekst" valign="top">
  149. <input type="submit" value=" Voeg toe " class="form" name="voegtoe"><input type="button" value=" wacht even " class="form" name="voegtoe_hidden" disabled style="display:none">
  150. </td>
  151. </tr>
  152. </table>
  153. </td>
  154. </tr>
  155. </table>
  156. </td>
  157. </tr>
  158. </table>
  159. </div>
  160. </form>
  161. <input type="Button" value=" Cancel " class="form" OnClick="self.close();">
  162. </td>
  163. </tr>
  164. </div>

0 antwoorden

Gesponsorde links
Er zijn nog geen reacties op dit bericht.
Je moet ingelogd zijn om een reactie te kunnen posten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.171s