Afficher une image binaire
Bonjour, via mon application je récupère les données binaire d'une photo (avatar d'un contact gmail), je souhaite ensuite utiliser ces données pour afficher l'image cependant j'ai apparemment un problème quelque part dans la transmission des données car rien ne s'affiche :/
J'ai donc deux controller : indexController et avatarController le premier affiche la liste des contacts avec logiquement l'image correspondante et le second sert à l'affiche de cette avatar.
J'ai deux classes, une Avatar et une Contact, la classe Contact possède toutes les infos sur un contacts (nom, mail, objet Avatar) et la classe Avatar comporte possède les données binaire de l'avatar et son type mime.
Contact :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
/**
* Recuperation du nom
* @return String
**/
public function getNom() {
return $this->_nom;
}
/**
* Recuperation du mail
* @return String
**/
public function getEmail() {
return $this->_email;
}
/**
* Recuperation de l'avatar
* @return My_ContactsGetter_Model_Avatar
**/
public function getAvatar() {
return $this->_avatar;
} |
Avatar :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
/**
* Recuperation des bytes
* @return String
**/
public function getDatas() {
return $this->_datas;
}
/**
* Recuperation du type mime de l'avatar
* @return String
**/
public function getType() {
return $this->_type;
} |
avatarController :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
public function indexAction()
{
// Désactive le layout
$this->_helper->layout->disableLayout();
if (!empty($mySession->avatar)){
$type = $mySession->avatar->getType(); // Type mime
$datas = $mySession->avatar->getDatas(); // Données binaire
$this->getResponse()->clearBody();
$this->getResponse()->setHeader('Content-Type', $type);
$this->getResponse()->appendBody($datas);
}
} |
Et ma vue du indexController :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
if (isset($this->contacts)){
foreach ($this->contacts as $contact) {
$mySession->avatar = $contact->getAvatar();
$mail = $contact->getEmail();
$nom = $contact->getNom();
echo "<a href=mailto:$mail>$nom</a>";
echo '<img src="avatar">';
echo '<br/>';
}
} |
Donc normalement en utilisant le echo '<img src="avatar">'; je devrait obtenir mon image...Mais la, non rien :((( meme pas de petite case avec une croix ou je ne sais quoi, nada
Help please:cry:
Merci d'avance à tous!