Welcome Guest, Not a member yet? Register   Sign In
Uploaded image, save in DB and disply link to image
#1

[eluser]mabright[/eluser]
I am trying to read an image that I have stored in my database in a BLOB field. I have read a few post but have not found what I need to accomplish this task.

I have a database table as follows and I would like to display a link on my page that links to the uploaded image(image that is stored in the BLOB) and will display the image when clicked.

Code:
CREATE TABLE `xvb_msg_attachments` (
  `id` int(11) NOT NULL,
  `atid` int(11) NOT NULL auto_increment,
  `image_name` varchar(50) NOT NULL,
  ` image_type` varchar(25) NOT NULL,
  `image_size` varchar(25) NOT NULL,
  `image_ctgy` varchar(25) NOT NULL,
  `image` blob NOT NULL,
  `created_on` datetime NOT NULL,
  PRIMARY KEY  (`id`,`atid`)
#2

[eluser]Rob Gordijn[/eluser]
ok, just some quick thougts:

- fopen and fread the file-contents
- $data = chunk_split(base64_encode($file_content));
- store $data in your blob
- get and store the other info (like type, size, etc)
- for displaying, select all the data, echo base64_decode($data);
- dont forget to send the appropriate headers (based on file type)

cheers!
#3

[eluser]Colin Williams[/eluser]
Rob has a good overview for you. You'll simply want a controller function that does the query and echo, and then your links will point at that controller/function/id URL, just like if it were any other callback in codeigniter
#4

[eluser]Fero[/eluser]
Hi,

What else except type and size should i save?




Theme © iAndrew 2016 - Forum software by © MyBB