I am in need of some guidence with a problem that I am having. I have created a user form in PHP that allows the user to upload an image file to a mysql database. The database is setout to stor image data as a mediumblob. My problem is that I cannot find a way to dispaly all my database records and their images. Most guides online seem very over engineered and I was hoping there was an easier way.
For your inforamtion I have included the code of my data submission form.
Submission Form
<form method="post" enctype="multipart/form-data" action="upload.php">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
Upload.php
Code: Select all
<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include '../sv/dbconfig.php';
include '../sv/opendb.php';
$query = "INSERT INTO Cars (ImageFile) ".
"VALUES ('$content')";
mysql_query($query) or die('Error, query failed');
include '../sv/closedb.php';
echo "<br>File $fileName uploaded<br>";
}
?>