Hi Bastien
I created the database with the file exactly as posted and created an upload script accordingly:
<?php
if($POST['sent'])
{
if(!is_uploaded_file($FILES['bin_data']['tmp_name']))
{$error="<br>No file has been uploaded";}
else
{
if($_FILES['bin_data']['size']>1000000)
{$error.="<br>The file is too big;";}
}//ende ELSE no file has been uploaded
if(!$error)
{
$link = mysql_connect("localhost", "root", "pass");
mysql_select_db("images", $link);
$datei=fopen($FILES['bin_data']['tmp_name'], 'rb');
$data=addslashes(fread( $datei, $FILES['bin_data']['size']));
$sql=" INSERT INTO binary_data (description, filename, filesize, filetype)
values ('".$POST['description']."' , '".$POST['filename']."' , '".$POST['size']."' ,'".$FILES['bin_data']['type']."')";
if(!mysql_query($sql, $link))
{$fehler.="<br>upload failed due to database failure, please try again later<br>";}
}
if($fehler){echo "<h2><font color=\"red\">".$fehler."</font></h2>";}
else
{
echo "<h2><font color=\"blue\">file upload has been successful</font></h2>";
unset($POST['description']);
unset($POST['filename']);
unset($POST['filesize']);
}
}//end $POST['sent']
?>
<h1>file upload</h1>
<form action="<?php echo $SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="sent" value="1" />
<p>Filename</p>
<input type="text" name="filename" size="50" value="<?php echo $POST['filename'] ; ?>"><br>
<p>Description</p>
<input type="text" name="description" size="50" value="<?php echo $_POST['description']; ?>"> <br />
<p>Choose file</p>
<input type="file" name="bin_data" size="50" /><br />
<br />
<input type="submit" value="submit" /><br />
<input type="reset" value="reset" />
</form>
here is the show_images.php
<?php
mysql_connect("localhost", "root", "pass") or
die ("Could not connect to database.");
mysql_select_db("images") or
die ("Cannot select database.");
//check to see if the id is passed
if(isset($GET['id']))
{
$id=$GET['id'];
$query = "select bin_data, filetype from binary_data where id=$id";
//echo $query;
$result = mysql_query($query) or
die(mysql_error();
$row = mysql_fetch_array($result);
{
$data = $row['bin_data'];
$type = $row['filetype'];
}
if ($type=="pjpeg") $type = "jpeg";
if ($type=="gif") $type = "gif";
Header( "Content-type: $type");
echo $data;
}
?>
and the show_desc.php
<?php
require("connect.php");
// you may have to modify login information for your database server
$query = "select description, id from binary_data ";
$result = mysql_query($query);
while ($rows = MYSQL_FETCH_ARRAY($result)) {
echo $rows['description'];
echo "<br><br>";
echo "<img src=\"show_image.php?id=".$rows['id']."\">\n";
}
I have a connect.php and that seems to be working fine, The script accesses the correct table, but only displays the images as boxes with red crosses.
Any help greatly appreciated, theanks!!!
Kat