login  Naam:   Wachtwoord: 
Registreer je!
 Forum

upload hulp nodig (Opgelost)

Offline gwenn - 29/10/2008 23:15 (laatste wijziging 29/10/2008 23:17)
Avatar van gwennGouden medaille

Grafische interesse
Mijn vraag/probleem?

Hoe kan ik nu de afbeeldingen "pics" die ik upload koppelen aan de andere database "for sale". Er kunnen ook meerdere afbeeldingen bij een for sale item zijn??



CREATE TABLE `pics` (
id INT NOT NULL AUTO_INCREMENT,
forsale_id INT NOT NULL,
name VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
size INT NOT NULL,
content MEDIUMBLOB NOT NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

  1. <?php $query=mysql_query("SELECT * FROM forsale WHERE id = '".$_GET['id']."'");
  2. if(mysql_num_rows($query)) {
  3. $bericht = mysql_fetch_object($query);
  4. echo"<table><tr class=\"nieuws\">
  5.  
  6. <td width=\"40\" align=\"center\">$bericht->id</td>
  7. <td width=\"80\" align=\"center\">$bericht->stockno</td>
  8.  
  9. <td width=\"80\" align=\"center\">$bericht->name</td>
  10. <td width=\"80\" align=\"center\">$bericht->breeder</td>
  11.  
  12. </tr></table>";
  13.  
  14. }
  15.  
  16. $query=mysql_query("SELECT * FROM pics WHERE koiforsale_id='".$_GET['id']."'");
  17. if(mysql_num_rows($query)) {
  18. $ber = mysql_fetch_object($query);
  19. echo"<table><tr class=\"nieuws\">
  20.  
  21. <td width=\"40\" align=\"center\">$ber->forsale_id</td>
  22. <td width=\"80\" align=\"center\"><img src=\"forsale/thumbs/$ber->name\".jpg alt=\"\" /></td>
  23.  
  24. </tr></table>";
  25.  
  26.  
  27. }
  28.  
  29. if(IsSet($_POST['submit']) && $_FILES['userfile']['size'] > 0) {
  30.  
  31. $fileName = addslashes($fileName);
  32. $content = addslashes($content);
  33. }
  34.  
  35. // Maak query om gegevens in tabel te stoppen
  36. $query = "INSERT INTO pics ( name, size, type, content) VALUES ( '$fileName', '$fileSize', '$fileType', '$content')";
  37.  
  38. // Voer query uit
  39. mysql_query($query) or die (mysql_error());
  40.  
  41. // De ID van deze insert
  42. $id = mysql_insert_id();
  43.  
  44. echo "Your picture is succesfull added.";
  45.  
  46. $uploadDir = '/www/htdocs/beta/content/forsale/';
  47.  
  48. $file = $_FILES['userfile']['name'];
  49. $tmpName = $_FILES['userfile']['tmp_name'];
  50. $fileSize = $_FILES['userfile']['size'];
  51. $fileType = $_FILES['userfile']['type'];
  52.  
  53. $fileName = $file;
  54. $fileName = $id.".jpg";
  55.  
  56. // the files will be saved in filePath
  57. $content = $uploadDir . $fileName;
  58.  
  59.  
  60.  
  61. // move the files to the specified directory
  62. // if the upload directory is not writable or
  63. // something else went wrong $result will be false
  64. $result = move_uploaded_file($tmpName, $content);
  65. if (!$result) {
  66. echo "Error uploading file";
  67. }
  68.  
  69. } else {
  70.  
  71. echo"
  72.  
  73. <FORM ACTION=\"pictures.php\" METHOD=\"post\" enctype=\"multipart/form-data\">
  74. <table>
  75. <tr>
  76. <td><b>Foto:</b></td><td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"2000000\">
  77. <INPUT TYPE=\"file\" NAME=\"userfile\" SIZE=30 MAXLENGTH=150 id=\"userfile\"></td>
  78. </tr>
  79. <tr>
  80. <td><input type=\"submit\" value=\"add picture\" name=\"submit\"></td>
  81. </tr>
  82. </table>
  83.  
  84. </FORM> ";
  85.  
  86. }
  87. ?>

1 antwoord

Gesponsorde links
Offline MiST - 30/10/2008 08:09
Avatar van MiST Lid Foreign key instellen en joinen?
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.209s