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 ;
<?php $query=mysql_query("SELECT * FROM forsale WHERE id = '".$_GET['id']."'");
if(mysql_num_rows($query)) {
$bericht = mysql_fetch_object($query);
echo"<table><tr class=\"nieuws\">
<td width=\"40\" align=\"center\">$bericht->id</td>
<td width=\"80\" align=\"center\">$bericht->stockno</td>
<td width=\"80\" align=\"center\">$bericht->name</td>
<td width=\"80\" align=\"center\">$bericht->breeder</td>
</tr></table>";
}
$query=mysql_query("SELECT * FROM pics WHERE koiforsale_id='".$_GET['id']."'");
if(mysql_num_rows($query)) {
$ber = mysql_fetch_object($query);
echo"<table><tr class=\"nieuws\">
<td width=\"40\" align=\"center\">$ber->forsale_id</td>
<td width=\"80\" align=\"center\"><img src=\"forsale/thumbs/$ber->name\".jpg alt=\"\" /></td>
</tr></table>";
}
if(IsSet($_POST['submit']) && $_FILES['userfile']['size'] > 0) {
if(!get_magic_quotes_gpc()) {
$fileName = addslashes($fileName);
$content = addslashes($content);
}
// Maak query om gegevens in tabel te stoppen
$query = "INSERT INTO pics ( name, size, type, content) VALUES ( '$fileName', '$fileSize', '$fileType', '$content')";
// Voer query uit
mysql_query($query) or die (mysql_error());
// De ID van deze insert
$id = mysql_insert_id();
echo "Your picture is succesfull added.";
$uploadDir = '/www/htdocs/beta/content/forsale/';
$file = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fileName = $file;
$fileName = $id.".jpg";
// the files will be saved in filePath
$content = $uploadDir . $fileName;
// move the files to the specified directory
// if the upload directory is not writable or
// something else went wrong $result will be false
$result = move_uploaded_file($tmpName, $content);
if (!$result) {
echo "Error uploading file";
exit;
}
} else {
echo"
<FORM ACTION=\"pictures.php\" METHOD=\"post\" enctype=\"multipart/form-data\">
<table>
<tr>
<td><b>Foto:</b></td><td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"2000000\">
<INPUT TYPE=\"file\" NAME=\"userfile\" SIZE=30 MAXLENGTH=150 id=\"userfile\"></td>
</tr>
<tr>
<td><input type=\"submit\" value=\"add picture\" name=\"submit\"></td>
</tr>
</table>
</FORM> ";
}
?>
<?php $query=mysql_query("SELECT * FROM forsale WHERE id = '".$_GET['id']."'"); echo"<table><tr class=\"nieuws\"> <td width=\"40\" align=\"center\">$bericht->id</td> <td width=\"80\" align=\"center\">$bericht->stockno</td> <td width=\"80\" align=\"center\">$bericht->name</td> <td width=\"80\" align=\"center\">$bericht->breeder</td> </tr></table>"; } $query=mysql_query("SELECT * FROM pics WHERE koiforsale_id='".$_GET['id']."'"); echo"<table><tr class=\"nieuws\"> <td width=\"40\" align=\"center\">$ber->forsale_id</td> <td width=\"80\" align=\"center\"><img src=\"forsale/thumbs/$ber->name\".jpg alt=\"\" /></td> </tr></table>"; } if(IsSet($_POST['submit']) && $_FILES['userfile']['size'] > 0) { } // Maak query om gegevens in tabel te stoppen $query = "INSERT INTO pics ( name, size, type, content) VALUES ( '$fileName', '$fileSize', '$fileType', '$content')"; // Voer query uit // De ID van deze insert echo "Your picture is succesfull added."; $uploadDir = '/www/htdocs/beta/content/forsale/'; $file = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fileName = $file; $fileName = $id.".jpg"; // the files will be saved in filePath $content = $uploadDir . $fileName; // move the files to the specified directory // if the upload directory is not writable or // something else went wrong $result will be false if (!$result) { echo "Error uploading file"; } } else { <FORM ACTION=\"pictures.php\" METHOD=\"post\" enctype=\"multipart/form-data\"> <table> <tr> <td><b>Foto:</b></td><td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"2000000\"> <INPUT TYPE=\"file\" NAME=\"userfile\" SIZE=30 MAXLENGTH=150 id=\"userfile\"></td> </tr> <tr> <td><input type=\"submit\" value=\"add picture\" name=\"submit\"></td> </tr> </table> </FORM> "; } ?>
|