faqts : Computers : Programming : Languages : PHP : Database Backed Sites : Interbase

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

19 of 27 people (70%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How do I insert an image into an Interbase database?

Mar 28th, 2001 00:26
Tomeu Vidal, sriki g, Ben Udall,


You have a table with a BLOB field for store the image,

CREATE TABLE IMAGE(
IMAGEID INTEGER NOT NULL,
IMAGE BLOB,
CONSTRAINT PK_IMAGE PRIMARY KEY(IMAGEID)
);

Supose we have a trigger for fill the IMAGEID from a Generator,
so we only have to worry about filling the blob content.

You have an HTML page with a FORM as the following ....

<FORM NAME="fImage" ACTION="postImage.php" ENCTYPE="multipart/form-
data">
<INPUT TYPE="FILE" NAME="fileSource">
<INPUT TYPE="SUBMIT">
</FORM>

Form must have ENCTYPE set to multipart/form-data to permit
the image file uploading.


Next step is postImage.php PHP sript:


<?
  // Connecto to DB
  $db = ibase_connect($database, $user, $passwd);


  //preparing the insert statement
  $st = ibase_prepare($db, "INSERT INTO IMAGE(IMAGE) VALUES(?)");


  //Blob handle stuff
  $blobImagenStr = ibase_blob_import($db,fopen($fileSource, "r"));


  //Execute the insert statement and freeing the prepared statement.
  ibase_execute($st,$blobIdStr)
  ibase_free_query($st);


  //Closing the database ....
  ibase_close($db);


  //A message ....
  echo ("Ok");
?>