I have JPEG/PNG small file which is stored in the mysql database field picture as following:
$fdata = '';
if (isset($_FILES['picture']) && $_FILES['picture']['size'] > 0) {
$tmpName = $_FILES['picture']['tmp_name'];
$fp = fopen($tmpName, 'r');
$fdata = fread($fp, filesize($tmpName));
$fdata = addslashes($fdata);
fclose($fp);
//$sl = "INSERT INTO image (image)VALUES ( '$data')", $connection);
print "Thank you, your file has been uploaded.";
} else {
print "No image selected/uploaded";
}
// Update the table
$this->db->update('users',
array('password' => $_POST['password'],
'picture' => $fdata),
array('username=?' => $ouser ));
But problem is now how do i output that "picture field" value from the database into real picture for web browsers?
EDIT 1:
Simply echo does not render the picture in browser
EDIT 2:
public function pictureshowAction() {
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$this->_response->setHeader('Access-Control-Allow-Origin', '*');
$this->db = Application_Model_Db::db_load();
$ouser = $_GET['ousername'];
$sql = "select *From users where username='{$ouser}' limit 1";
$result = $this->db->fetchAll($sql);
if (count($result) > 0 ) {
$picture = $result[0]['picture'];
//$content = $picture;
$content = stripslashes($picture);
} else {
$content = '';
}
//echo $content;
$this->getResponse()
->setHeader('Content-Type', 'image/jpg')
->setBody($content)
->sendResponse();
exit;
}