-2

I am trying to store and retrieve photos from a MySql database.
Can someone tell me how to do this?

  • 1st Solution that am uisng now :
    I am using Zend_File_Transfer and Zend_Form_Element_File in my forms to upload files to a specified folder, saving the full path and the mime type in my database.
    (File stored in server, and file info stored in database)
  • 2nd Solution that i whant to know how to do it :
    I am searchig for how to implement a method to retrieve data from a Mysql BLOB field (containing my photo file) and display it in my view in an <img> tag if possible.
    (File and info stored in database)
Salem
  • 331
  • 1
  • 7
  • 21
  • What you have tried? What are you want? – Alex Pliutau Mar 14 '12 at 14:03
  • Too broad and too vague. Specify your question by asking what problems you are running into when implementing the methods yourself – Pieter Mar 14 '12 at 19:44
  • There's also what seems like a contradiction in your question - you've said you're storing the file path and mime type in the database, but then you say you have the photo 'file' stored in a MySQL BLOB field? – Tim Fountain Mar 14 '12 at 22:44

1 Answers1

0

i resolve my problem like folowing:

  1. Storing my photo file in a BLOB field into database (using traditional Zend_Form, Zend_File_Transfer and Zend_Form_Element_File)
  2. when rerieving this file data from my database to render it in my view, i use something like this:

    <img src="data:<?php echo $dbData->fileMimeType; ?>;base64,<?php echo base64_encode($dbData->fileData); ?>" />
    the html result is like this:
    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaQAAAGkCAYAAAB+TFE1AAA....(Data)....LKf3f6ZTf/akvtxuC8HL7kcUkjg9UAOG2nxejCHTa2518Mju"\>

so easy and so simple :)

Salem
  • 331
  • 1
  • 7
  • 21