Image Uploaded and Retrieve

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Yanayaya
Forum Commoner
Posts: 42
Joined: Tue Dec 02, 2008 7:49 am

Image Uploaded and Retrieve

Post by Yanayaya »

Hello Everyone,

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>";
} 
?>
The upload.php only inserts in the image at this time as I have not moved on to the text data yet but I dont have a problem with that. I just need to be able to pull these images back and display them.
jankidudel
Forum Commoner
Posts: 91
Joined: Sat Oct 16, 2010 4:30 pm
Location: Lithuania, Vilnius

Re: Image Uploaded and Retrieve

Post by jankidudel »

It's not hard, just like any other image inserting echo "<img src=' http://www.example.com/[path to the image]' >" ;


http://www.daniweb.com/forums/thread930 ... 93043.html
Post Reply