Hallo zusammen,
ich habe wieder mal ein Problem..
Ich habe im Internet folgendes Script für Bilder in db speichern gefunden.
Leider bekomme ich keine bilder in die datenbank.
CREATE TABLE binary_data (
id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
description CHAR(50),
bin_data LONGBLOB,
filename CHAR(50),
filesize CHAR(50),
filetype CHAR(50)
);
PHP
<?php
?>
<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) {
MYSQL_CONNECT("localhost","root","");
mysql_select_db("binary_data");
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$f orm_data_size','$form_data_type')");
$id= mysql_insert_id();
print "
This file has the following Database ID: $id";
MYSQL_CLOSE();
} else {
// else show the form to submit new data:
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
File Description:
<input type="text" name="form_description" size="40">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
File to upload/store in database:
<input type="file" name="form_data" size="40">
<input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
</body>
</html>
Alles anzeigen
Und hier die auslese Datei
PHP
<?php
if($id) {
// you may have to modify login information for your database server:
@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("binary_data");
$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;
};
?>
Alles anzeigen
Vielleicht kommt ihr auf einen Fehler drauf....
Danke im Vorraus