Re: images
| From: | Hatem Ben | Date: | Tue, 15 Oct 2002 19:46:00 +0000 |
| Subject: | Re: images | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-22433@lists.php.net to get a copy of this message | ||
hello,
you can do it this way (using mysql):
<?php
/*
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)
) TYPE=MyISAM;
*/
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\">
</form>";
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);
}
else
$image = NULL;
$query = "INSERT INTO images VALUES (NULL, '$imgname', '$imgtype',
'$image')";
$result = mysql_query( $query ) or die("Query failed");
echo "Hope this will help ;)";
}
?>
Regards,
Hatem
----- Original Message -----
From: "Edward Peloke" <epeloke@echoman.com>
To: <php-db@lists.php.net>
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