First, I wouldn't recommend storing images in your database. It creates bloat, slows it down, makes backup difficult and requires duplication if needed for other purposes. You are much better to upload the images to a directory and just save the link
If you do must upload them to your database, there is a PEAR program to help
$abpath = "/home/YOURuserNAME/public_html/images/"; //Absolute path to where images are uploaded.
require 'HTTP/Upload.php';
$upload = new HTTP_Upload('en'); // Language for error messages
$file = $upload->getFiles('userfile'); // return a file object or error
if (PEAR::isError($file)) { die ($file->getMessage());}// Check if the file is a valid upload
$properties = $file->getProp();
$extension = $file->getProp('ext');
if ($file->isValid()) { // this method will return the name of the file you moved, // useful to save the name in a database
$file_name = $file->moveTo($abpath);
if (PEAR::isError($file_name)) { die ($file_name->getMessage()); }}
$data = addslashes(fread(fopen($abpath.$file_name, "r"), $properties[size]));
Below is the query that I use for uploads, although it probably has a lot more fields of data than you need. Feel free to pare it down.
$file_query="insert into $db.files ( file_name, file_display_name, file_url, file_file, file_extension, file_size, file_type, file_comments, file_saved_by, file_date_saved, file_start_date, file_end_date, file_status, file_chains, file_show, file_feature) values ('$properties[name]', '$file_display_name', '$abpath', '$data', '$properties[ext]', '$properties[size]', '$properties[type]', '$comments', '$emp', '$date_saved', '$start_date', '$end_date', '$file_status', '$file_chains', '$file_show', '$file_feature') ";
$result_insert_files=mysql_query($file_query, $conn) or die("line 36 ".mysql_error());
To display the images create a PHP program with a name like "show_images.php"
// add your database connection code here.
$sql = "SELECT file_file, file_type, file_name, file_size FROM files WHERE file_id=$id_files";
$result = @mysql_query($sql, $conn) or die("line 9 ".mysql_error());
$data = @mysql_result($result, 0, "file_file");
$name = @mysql_result($result, 0, "file_name");
$size = @mysql_result($result, 0, "file_size");
$type = @mysql_result($result, 0, "file_type");
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
?>
To view the image
echo" iles=$image_id\">";