I am trying to perform DB operation with images and have used some of the scripts available on-line.
Mysteriously, I get no error messages whatsoever, neither do I get any results. Even when I insert a row manually consisting of an image, and when I attempt to display the query nothing comes up. No image, no error; just a blank page.
Where can I start looking into to find out what's going on?
This is the index page that supposed to view images with a link to upload:
PHP:
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Browse Upload Files</title>
</head>
<body bgcolor="#CCFF99">
<?php
include 'db.inc';
$query = "SELECT id, shortName, mimeName FROM files";
if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
showerror();
if (!mysql_select_db("files", $connection))
showerror();
if (!($result = @ mysql_query ($query, $connection)))
showerror();
?>
<h1>Image database</h1>
<h3>Click <a href="insert.php">here</a> to
upload an image.</h3>
<?php
if ($row = @ mysql_fetch_array($result))
{
?>
<table>
<col span="1" align="right">
<tr>
<th>Short description</th>
<th>File type</th>
<th>Image</th>
</tr>
<?php
do
{
?>
<tr>
<td><?php echo "{$row["shortName"]}";?></td>
<td><?php echo "{$row["mimeName"]}";?></td>
<td><?php echo "<img src=\"view.php?file={$row["id"]}\">";?></td>
</tr>
<?php
} while ($row = @ mysql_fetch_array($result));
?>
</table>
<?php
} // if mysql_fetch_array()
else
echo "<h3>There are no images to display</h3>\n";
?>
</body>
</html>
And here's the view.php:
PHP:
<?php
include 'db.inc';
$file = clean($file, 4);
if (empty($file))
exit;
if (!($connection = @ mysql_pconnect($hostName,
$username,
$password)))
showerror();
if (!mysql_select_db("files", $connection))
showerror();
$query = "SELECT mimeType, fileContents FROM files
WHERE id = $file";
if (!($result = @ mysql_query ($query,$connection)))
showerror();
$data = @ mysql_fetch_array($result);
if (!empty($data["fileContents"]))
{
// Output the MIME header
header("Content-Type: {$data["mimeType"]}");
// Output the image
echo $data["fileContents"];
}
?>
Here's the table difinition:
PHP:
CREATE TABLE files (
id int(11) NOT NULL auto_increment,
shortName varchar(50) default NULL,
mimeType varchar(30) default NULL,
mimeName varchar(50) default NULL,
fileContents blob,
PRIMARY KEY (id)
) TYPE=MyISAM;
I have a few rows loaded manually, but can't load via the page. Again, no error no result.
Thanks in advance.