Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I save files to MySQL tables?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I would like to store some files within a MySQL table. They're graphics files, but they're small -- around 60 x 60 pixels each. These are my questions...

1) Is this possible?
2) What's the syntax for saving a file to a MySQL table?
3) What's the syntax for retrieving files from MySQL table?
4) Would it be faster/better to send/retrieve such files on a public FTP site if one's available?
 
hi JD,

(1) yes it's possible.
(2) for saving file into mysql :
$image_data = addslashes(fread(fopen($image_file,"r"), filesize($image_file)));
$SQL = "INSERT INTO image_table (image,image_type,image_name)
VALUES ('$image_data','$image_type','$image_name')";

(3) for view'n images
$SQL = "SELECT image,image_type FROM image_table
WHERE image_id='$image_id'";
note : image_id is autoincrement field.
note : this is php code. and you'd put this in a seperate
file (ie. get_image.php). to view the image from a
web page you'd : <img src=$get_image.php?image_id=1>
------- start code ------
$result = mysql_query($SQL,$dbh);
$record = mysql_fetch_array($result);
$image_type = $record[image_type];
$image = $record[image];

Header( &quot;Content-type: $image_type&quot;);
echo $image;

cheers
ken
devnull22

--
Apparently if you play the Windows NT CD backwards you hear satanic messages. If you think that's bad, play it forwards and it installs Windows NT !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top