I have been reading the article by Florian Dittmer.
http://www.phpbuilder.net/columns/florian19991014.php3
I have used the mod that Patrick Kebekus made for it to be used for php4.32.
http://www.phpbuilder.net/annotate/message.php3?id=1017206
It works fine and loads into mysql. Except that nothing gets inserted into the "description" column of the database, which is a minor problem.
My biggest problem is that the getdata.php3 scripts in Florians article does not seem to work. I am assuming that it is because it is not modified to be used with php 4.
When I try to view the image in the mysql database by making an html to view the image source, I do not get the image that is in mysql. I get nothing except for the standard image error - red[x] image.
Can anyone tell me what is wrong with the getdata script, and why it will not show the image from mysql?
Also I would like to know why there is no info. inserted into the "description" column in mysql when the file is submitted?
Here is my php 4 modified store.php script:
<?php
// store.php - by Florian Dittmer <dittmer@gmx.net>
// moded for php4 by [email]Patrick.MKC@gmx.de[/email]
// Example php script to demonstrate the storing of binary files into
// an sql database. More information can be found at [url]http://www.phpbuilder.com/[/url]
?>
<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 (isset($_REQUEST['submit'])) {
// connect to the database
// (you may have to adjust the hostname,username or password)
MYSQL_CONNECT("localhost","root","mshp");
mysql_select_db("MSHP");
$data = addslashes(fread(fopen($_FILES['form_data']['tmp_name'], "r"), $_FILES['form_data']['size']));
$result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('".$form_description."','".$data."','".$_FILES['form_data']['name']."','".$_FILES['form_data']['size']."','".$_FILES['form_data']['type']."')");
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
MYSQL_CLOSE();
} else {
// else show the form to submit new data:
?>
<form method="post" action="store.php" 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">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
</BODY>
</HTML>
Here is what I have for the getdata.php3 script
<?php
// getdata.php3 - by Florian Dittmer <dittmer@gmx.net>
// Example php script to demonstrate the direct passing of binary data
// to the user. More infos at [url]http://www.phpbuilder.com[/url]
// Syntax: getdata.php3?id=<id>
if($id) {
// you may have to modify login information for your database server:
@MYSQL_CONNECT("localhost","root","mshp");
@mysql_select_db("MSHP");
$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;
};
?>
And here is my HTML page to test the image in the mysql database:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, [url]www.pspad.com[/url]">
<title>Untitled</title>
</head>
<body>
<img src="getdata.php3?id=3">
</body>
</html>
Any help would be greatly appreciated.
Thanks!