Hallo,
ich speichere ein Bild in ner Datenbank:
<?php
if ($submit) {
mysql_connect("host","root","password");
mysql_select_db("test");
$data = addslashes(fread(fopen($form_data, "r"), filesize$(form_data)));
$result=mysql_query("INSERT INTO test (description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
} else {
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
<input type="text" name="form_description" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="file" name="form_data" size="40">
<input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
soweit so gut, das klappt. Nun ruf ich das Bild wieder ab:
<img src="getdata.php3?id=3">
Code getdata.php:
if($id) {
mysql_connect("host","root","password");
mysql_select_db("test");
$query = "select bin_data,filetype from binary_data where id=$id";
$result = mysql_query($query);
$data = mysql_result($result,0,"bin_data");
$type = mysql_result($result,0,"filetype");
Header( "Content-type: $type");
echo $data;
};
Hier bekomm ich nur ein weisses Kästchen mit nem roten X angezeigt. Schreib ich den DB Inhalt aber in ein File wird die Sache richtig angezeigt.
Wo liegt mein Fehler?
Danke und Gruß
Ralf Kronen