bilder speichern

G

Guest

Guest
Hallo,

im Augenblick versuche ich mal zur Abwechslung hochgeladene Bilder in der Mysql-Datenbank zu speichern und hab dafür folgenden Code gefunden, der bei anderen wie's scheint auch funktioniert. Gespeichert wird das Bild, jedoch wird es im ie nicht angezeigt und im firefox erscheint die Meldung, das Bild kann nicht angezeigt werden, denn es hätte Fehler, wenn man den Zeigeteil im code in eine Extradatei auslagert. Weiss jemand weiter?


CODE

<html>
<head><title>Store binary data into SQL Database</title></head>
<body>

<?php
// code that will be executed if the form has been submitted:

if ($submit) {

include 'fincyclass.inc';
$aha=new db();
$link = mysql_connect($aha->host,$aha->user,$aha->pass) or die("Keine Verbindung möglich: " . mysql_error());
mysql_select_db($aha->db) or die("Auswahl der Datenbank fehlgeschlagen".mysql_error());

   $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));

   $result=MYSQL_QUERY("INSERT INTO binary_data (bin_data,filename,filesize,filetype) ".
       "VALUES ('$data','$form_data_name','$form_data_size','$form_data_type')");

   $id= mysql_insert_id();
   print "<p>This file has the following Database ID: <b>$id</b>";



} else {

   // else show the form to submit new data:
?>

   <form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
   File Description:<br>
   <input type="text" name="form_description"  size="40">
   <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
   <br>File to upload/store in database:<br>
   <input type="file" name="form_data"  size="40">
   <p><input type="submit" name="submit" value="submit">
   </form>

<?php

}

if($id) {

   // you may have to modify login information for your database server:


   mysql_select_db("binary_data");

   $query = "select bin_data,filetype from binary_data where id=$id";
   $result = MYSQL_QUERY($query)or die(mysql_error());

   $data = MYSQL_RESULT($result,0,"bin_data");
   $type = MYSQL_RESULT($result,0,"filetype");

   Header( "Content-type: $type");
   echo $data;
mysql_close();
};

?>
</body>
</html>





Gruss Tümmel
 
Zurück
Oben