Re: images [Oops]
| From: | Hatem Ben | Date: | Tue, 15 Oct 2002 21:35:44 +0000 |
| Subject: | Re: images [Oops] | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-22439@lists.php.net to get a copy of this message | ||
Oops sorry for never testing before sending :P the script works fine
but there is a little change, there is a hiddent should be changed to hidden
in the form ;)
that's all,
enjoy
----- Original Message -----
From: "Hatem Ben" <reflex_news@yahoo.fr>
To: <php-db@lists.php.net>
Sent: Tuesday, October 15, 2002 9:46 PM
Subject: Re: [PHP-DB] images
> 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
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php