Re: Storing pictures in mySQL
> I am not sure what you explained. You mean that place PATH/filename.jpg to > picture field. isn't it? If yes, it is just a text. How can we explore that > picture thru web browser such as IE or Netscape? Thanks for the answer Your image would be in, say /usr/local/apache/htmldoc/images/simpletons/12.jpg and the row in your table might be USER_ID NAMEIMAGE_PATH -- 12 TAING /usr/local/pache/htmldoc/images/simpletons/12.jpg Which could be accessed with http://www.simpletonsrus.com/images/simpletons/12.jpg regards, P > > Regards > > Taing Nguon > > > > > > - > Before posting, please check: >http://www.mysql.com/manual.php (the manual) >http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Storing pictures in mySQL
On 05.04.2001 04:23:55 Taing Nguon wrote: > I am not sure what you explained. You mean that place PATH/filename.jpg to > picture field. isn't it? If yes, it is just a text. How can we explore that > picture thru web browser such as IE or Netscape? Thanks for the answer Well, he said that he has his setup in such a way, that Aliases in the apache config are created automatically to point to the users dir. Next he stores, let's say "user23443/askwar.jpg" in his database. When somebody wanted to watch this picture, the browser would request "user23443/askwar.jpg" and would get it right away, as it is accessible via the filesystem. At least that's how I understood it. - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Storing pictures in mySQL
>I would rather store the files on disk and the filenames in the database for more speed. >I'm a developer on a website which members have an uploaded image of theirself.. >We just have a image directory with filenames as [username].jpg >This dir is therefore easily mapped to the web with an Alias directive in the Apache config. I am not sure what you explained. You mean that place PATH/filename.jpg to picture field. isn't it? If yes, it is just a text. How can we explore that picture thru web browser such as IE or Netscape? Thanks for the answer Regards Taing Nguon - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Antwort: Storing pictures in mySQL
On 04.04.2001 11:21:46 Peter Skipworth wrote: > Ouch! I don't know if many people would recommend this method - that's a > fair bit of unnecesary overhead to place ony our server...depending, of > course, on how often these images are created/modified/read. Do you mean the base64 part, or what? Or are you talking about storing it in the database at all? BTW: Is your email adress correct? It got here as: [EMAIL PROTECTED] This looks strange. - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Antwort: Storing pictures in mySQL
You may look at the MySQL related code in phpAds from phpwizard.net: http://www.phpwizard.net/projects/phpAds/ It will bring you all you need in code, but I've tested that system on a website with 30 concurrent users with 2 ads (2 image SELECTs) per pageview and that was a bg performance buster. So, I still recommend you to place the image files in the filesystem and only the filenames in the database. (I use the PK for that table as filename, then you don't need to store the filenames either... ) Regards, Johan Andersson Consultant - Original Message - From: "Peter Skipworth" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: "Nicolas Villatte" <[EMAIL PROTECTED]>; "Mysql (E-mail)" <[EMAIL PROTECTED]> Sent: Wednesday, April 04, 2001 11:21 AM Subject: Re: Antwort: Storing pictures in mySQL > Ouch! I don't know if many people would recommend this method - that's a > fair bit of unnecesary overhead to place ony our server...depending, of > course, on how often these images are created/modified/read. > > P > > > > > > Here's how I do b) in PHP: > > > > 1) Get the MIME type of the image. > > 2) Read the binary file contents and store it in a PHP variable. > > 3) Base64 encode the binary data, so that there is no binary anymore, but just > > plain ASCII data. > > 4) Store the image in a MEDIUMTEXT or LONGTEXT column > > 5) Store the MIME type > > > > When I want to retrieve and display the image, I do: > > > > 1) Retrieve the MIME type > > 2) Retrieve the Base64 encoded binary > > 3) Decode the base64 ascii to get the binary > > 4) Print the MIME type in the header (if we're talking about HTML, that is) > > 5) Print the image > > > > Code: > > > > /* > > BinTable contains at least three columns: > > ID -> autoincrementing int > > MIME -> VARCHAR( 50 ) > > Bin -> MEDIUMTEXT > > */ > > > > function StoreImage( $MIME, $Binary ){ > > // Store the binary with the associated MIME type in a database > > // Returns the row id of the just inserted row > > > > $base64 = base64_encode( $Binary ); > > $q = "INSERT INTO BinTable ( MIME, Bin ) VALUES ("; > > $q .= "'" . $MIME . "'"; > > $q .= ", '" . $base64 . "'"; > > $q .= ")"; > > > > mysql_query( $q ); > > return( mysql_insert_id() ); > > } > > > > function PrintImage( $ID ){ > > // Retrieve the image with the assoc. ID from the BinTable table > > // Returns TRUE if everything was Okay; FALSE otherwise > > // Sideeffect: Prints the image with header to stdout > > > > $q = "SELECT MIME, Bin FROM BinTable WHERE ID = " . $ID; > > $rs = mysql_query( $q ); > > if ( mysql_num_rows( $rs ) ){ > > // There is something to return > > if( ! headers_sent() ){ > > // Headers have not yet been sent - we can go ahead > > $row = mysql_fetch_object( $rs ); > > $bin = base64_decode( $row->Bin ); > > header( "Content-Type: " . $row->MIME ); > > print $bin; > > $ret = TRUE; > > } else { > > // Headers have already been printed - cannot continue > > $ret = FALSE; > > } > > } else { > > $ret = FALSE; > > } > > return( $ret ); > > } > > > > // The following assumes, that there is a in the > > HTML form > > // Futher, there also needs to be a form element where the MIME Type is > > specified > > // I assume png > > if( is_uploaded_file( $image['tmp_name'] ) ){ > > // The file has been uploaded - safe to store in database > > > > // Get the size in bytes of uploaded file > > clearstatcache(); > > $fs = filesize( $image['tmp_name'] ); > > > > // Read file contents into a variable > > $fd = fopen( $image['tmp_name'], "r" ); > > $file_bin = fread( $fd, $fs ); > > > > // Close the file > > fclose( $fd ); > > > > // Store the image in the database > > $img_ig = StoreImage( $MIME, $file_bin ); > > > > // And also print it > > if( ! PrintImage( $img_id ) ){ > > echo "For some reason the image could not be printed!"; > > } > > } > > > > > > > > - > > Before posting, please check: > >http:/
Re: Antwort: Storing pictures in mySQL
Ouch! I don't know if many people would recommend this method - that's a fair bit of unnecesary overhead to place ony our server...depending, of course, on how often these images are created/modified/read. P > > Here's how I do b) in PHP: > > 1) Get the MIME type of the image. > 2) Read the binary file contents and store it in a PHP variable. > 3) Base64 encode the binary data, so that there is no binary anymore, but just > plain ASCII data. > 4) Store the image in a MEDIUMTEXT or LONGTEXT column > 5) Store the MIME type > > When I want to retrieve and display the image, I do: > > 1) Retrieve the MIME type > 2) Retrieve the Base64 encoded binary > 3) Decode the base64 ascii to get the binary > 4) Print the MIME type in the header (if we're talking about HTML, that is) > 5) Print the image > > Code: > > /* > BinTable contains at least three columns: > ID -> autoincrementing int > MIME -> VARCHAR( 50 ) > Bin -> MEDIUMTEXT > */ > > function StoreImage( $MIME, $Binary ){ > // Store the binary with the associated MIME type in a database > // Returns the row id of the just inserted row > > $base64 = base64_encode( $Binary ); > $q = "INSERT INTO BinTable ( MIME, Bin ) VALUES ("; > $q .= "'" . $MIME . "'"; > $q .= ", '" . $base64 . "'"; > $q .= ")"; > > mysql_query( $q ); > return( mysql_insert_id() ); > } > > function PrintImage( $ID ){ > // Retrieve the image with the assoc. ID from the BinTable table > // Returns TRUE if everything was Okay; FALSE otherwise > // Sideeffect: Prints the image with header to stdout > > $q = "SELECT MIME, Bin FROM BinTable WHERE ID = " . $ID; > $rs = mysql_query( $q ); > if ( mysql_num_rows( $rs ) ){ > // There is something to return > if( ! headers_sent() ){ > // Headers have not yet been sent - we can go ahead > $row = mysql_fetch_object( $rs ); > $bin = base64_decode( $row->Bin ); > header( "Content-Type: " . $row->MIME ); > print $bin; > $ret = TRUE; > } else { > // Headers have already been printed - cannot continue > $ret = FALSE; > } > } else { > $ret = FALSE; > } > return( $ret ); > } > > // The following assumes, that there is a in the > HTML form > // Futher, there also needs to be a form element where the MIME Type is > specified > // I assume png > if( is_uploaded_file( $image['tmp_name'] ) ){ > // The file has been uploaded - safe to store in database > > // Get the size in bytes of uploaded file > clearstatcache(); > $fs = filesize( $image['tmp_name'] ); > > // Read file contents into a variable > $fd = fopen( $image['tmp_name'], "r" ); > $file_bin = fread( $fd, $fs ); > > // Close the file > fclose( $fd ); > > // Store the image in the database > $img_ig = StoreImage( $MIME, $file_bin ); > > // And also print it > if( ! PrintImage( $img_id ) ){ > echo "For some reason the image could not be printed!"; > } > } > > > > - > Before posting, please check: >http://www.mysql.com/manual.php (the manual) >http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Storing pictures in mySQL
I would rather store the files on disk and the filenames in the database for more speed. I'm a developer on a website which members have an uploaded image of theirself.. We just have a image directory with filenames as [username].jpg This dir is therefore easily mapped to the web with an Alias directive in the Apache config. But, that specific solution is good if you're going to use it for a website, maybe not for a java application or something.. Well, I hope you got some ideas now.. Just don't store the images in the database.. it will be a performance buster. Regards, Johan Andersson Consultant - Original Message - From: "B. van Ouwerkerk" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, April 04, 2001 9:01 AM Subject: Re: Storing pictures in mySQL > At 08:55 4-4-01 +0200, Nicolas Villatte wrote: > >is it possible? If yes, how ? > > Yes.. BLOB (BinaryLargeOBject) Check the archive, and manual. > > Bye, > > > B. > > > - > Before posting, please check: >http://www.mysql.com/manual.php (the manual) >http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Antwort: Storing pictures in mySQL
On 04.04.2001 08:55:04 Nicolas Villatte wrote: > is it possible? If yes, how ? Could someone *PLEASE* add this to the FAQ? There are two answers you'll get: a) Don't store the binary data in the database. Instead store nothing but the metadata. b) Also store the binary data in the database. Reasons: a) The filesystem is the best binary database there is. Accessing the filesystem to retrieve binary data is possibly faster than to do it thru MySQL. b) It's more convenient to have all the data in the database instead of spreading it all over. Here's how I do b) in PHP: 1) Get the MIME type of the image. 2) Read the binary file contents and store it in a PHP variable. 3) Base64 encode the binary data, so that there is no binary anymore, but just plain ASCII data. 4) Store the image in a MEDIUMTEXT or LONGTEXT column 5) Store the MIME type When I want to retrieve and display the image, I do: 1) Retrieve the MIME type 2) Retrieve the Base64 encoded binary 3) Decode the base64 ascii to get the binary 4) Print the MIME type in the header (if we're talking about HTML, that is) 5) Print the image Code: /* BinTable contains at least three columns: ID -> autoincrementing int MIME -> VARCHAR( 50 ) Bin -> MEDIUMTEXT */ function StoreImage( $MIME, $Binary ){ // Store the binary with the associated MIME type in a database // Returns the row id of the just inserted row $base64 = base64_encode( $Binary ); $q = "INSERT INTO BinTable ( MIME, Bin ) VALUES ("; $q .= "'" . $MIME . "'"; $q .= ", '" . $base64 . "'"; $q .= ")"; mysql_query( $q ); return( mysql_insert_id() ); } function PrintImage( $ID ){ // Retrieve the image with the assoc. ID from the BinTable table // Returns TRUE if everything was Okay; FALSE otherwise // Sideeffect: Prints the image with header to stdout $q = "SELECT MIME, Bin FROM BinTable WHERE ID = " . $ID; $rs = mysql_query( $q ); if ( mysql_num_rows( $rs ) ){ // There is something to return if( ! headers_sent() ){ // Headers have not yet been sent - we can go ahead $row = mysql_fetch_object( $rs ); $bin = base64_decode( $row->Bin ); header( "Content-Type: " . $row->MIME ); print $bin; $ret = TRUE; } else { // Headers have already been printed - cannot continue $ret = FALSE; } } else { $ret = FALSE; } return( $ret ); } // The following assumes, that there is a in the HTML form // Futher, there also needs to be a form element where the MIME Type is specified // I assume png if( is_uploaded_file( $image['tmp_name'] ) ){ // The file has been uploaded - safe to store in database // Get the size in bytes of uploaded file clearstatcache(); $fs = filesize( $image['tmp_name'] ); // Read file contents into a variable $fd = fopen( $image['tmp_name'], "r" ); $file_bin = fread( $fd, $fs ); // Close the file fclose( $fd ); // Store the image in the database $img_ig = StoreImage( $MIME, $file_bin ); // And also print it if( ! PrintImage( $img_id ) ){ echo "For some reason the image could not be printed!"; } } - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: Storing pictures in mySQL
At 08:55 4-4-01 +0200, Nicolas Villatte wrote: >is it possible? If yes, how ? Yes.. BLOB (BinaryLargeOBject) Check the archive, and manual. Bye, B. - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Storing pictures in mySQL
is it possible? If yes, how ? - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php