you can do it this way (using mysql):

create table images(
img_id int(4) NOT NULL auto_increment,
img_name varchar(60),
img_file_type varchar(10),
img_content blob,
PRIMARY KEY (img_id)
if (empty($imgfile) or $go!=="uploadimg")
// Generate the form to upload the image
$form = "<form method=\"post\" action=\"\" enctype=\"multipart/form-data\">
Specify a name for your image : <input type=\"text\" name=\"imgname\"><br/>
Select your image file : <input name=\"imgfile\" type=\"file\"><br/>
<input type=\"submit\" value=\"Submit\">
<input type=\"hiddent\" name=\"go\" value=\"uploadimg\">
echo $form;
} else {
// You have an image that you can insert it in database
/* Connecting, selecting database */
$link = @mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die("Could not connect");
@mysql_select_db("my_database") or die("Could not select database");
// if the file uploaded ?
if (is_uploaded_file($imgfile))
// Open the uploaded file
$file = fopen($imgfile, "r");
// you can get the $imgtype also here ;)
// Read in the uploaded file
$image = fread($file, filesize($imgfile));
// Escape special characters in the file
$image = AddSlashes($image);
$image = NULL;
$query = "INSERT INTO images VALUES (NULL, '$imgname', '$imgtype',
$result = mysql_query( $query ) or die("Query failed");
echo "Hope this will help ;)";


----- Original Message -----
From: "Edward Peloke" <[EMAIL PROTECTED]>
Sent: Tuesday, October 15, 2002 9:23 PM
Subject: [PHP-DB] images

> How can I allow the user to upload images to a php website and have the
> image stored in the mysql db?
> Thanks,
> Eddie
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to