[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Sheflug] Putting piccies in mysql/php
On Saturday 03 Aug 2002 12:37 pm, José Luis Gómez Dans wrote:
> I have now realised that I can store pics as binary data in MySQL
> tables as BLOBs. Now, I can store them in the DB, but has anoyone got
> any references to helpful examples?
The Phorum uses them for all it's images within articles. However, because I
use a small class library to allow me to access them, the code itself would
probably not prove useful.
However, in order for the most common (I think) use of a MySQL image table to
be fulfilled, to output it via HTTP (using Perl, PHP, or something of your
own devising) simply output a 'content-type: ' header populated with the
filetype field, then just print the binary data.
Here is a minimalist table to hold one. The filetype is generally the mime
type, although it can be anything you need. The filename length of 50 might
be a bit stingy, or a bit roomy. Depends on the system.
The rest is obvious, I think :)
CREATE TABLE image (
id int(11) NOT NULL auto_increment,
detail longblob NOT NULL,
filename varchar(50) NOT NULL default '',
filetype varchar(50) NOT NULL default '',
filesize int(11) NOT NULL default '',
PRIMARY KEY (image_id)
) TYPE=MyISAM;
HTH
Craig
___________________________________________________________________
Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html
GNU the choice of a complete generation.