Hi
I saw the tutorial for inserting and retreiving messages in the message regarding retreiving images from a database.
http://www.phpbuilder.com/columns/florian19991014.php3
I tried to follow the tutorial, and created the exact same table as in the tutorial in a database called cmpakris. In the version of php installed on the server I use, register_globals is turned off, so for instance instead of using if($submit) i have to use if($_POST["submit"]) and so on.
When running the script only the fields id, description and bin_data is inserted into the table, and the followiong error messages occur:
Warning: filesize() [function.filesize]: Stat failed for (errno=2 - No such file or directory) in /home/ftpserver/www/homepage/student/cmpakris/store.php3 on line 15
Warning: fread(): supplied argument is not a valid stream resource in /home/ftpserver/www/homepage/student/cmpakris/store.php3 on line 15
Below is the complete code, anybody who knows why it is not working?
<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>
<?php
if($POST["submit"])
{
$form_description=$POST['form_description'];
$form_data=$_POST['form_data'];
MYSQL_CONNECT("localhost","cmpakris","");
mysql_select_db("cmpakris");
$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','$form_data_size','$form_data_type')");
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
MYSQL_CLOSE();
} else {
?>
<form method="post" action="store.php3" 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
}
?>
</BODY>
</HTML>
Regards,
BettyB