how to view image stored in data zf2

129 views Asked by At

i have an image to display in view, when i put it in public/assets/img folder and writing in view(.phtml) enclosed code it works:

<img src="/assets/img/logo.jpg"  width="150" height="150" class="img-circle pull-left" alt="<?= $fournisseur->intitule ?>"  />

I want to put the images in data/img folder and display it in my view, how can i display it in view i tried with thise code, deleting data in path but no image view:

<img src="/data/img/logo.jpg"  width="150" height="150" class="img-circle pull-left" alt="<?= $fournisseur->intitule ?>"  />

i thought to create a controller for image:

public function imageAction()
{
    /** get id by url  **/
 $imageContent = file_get_contents('./data/img/logo.jpg');
    /** set file to reponse   **/
    $response->setContent($imageContent);
    /**  creat header **/
    $response
        ->getHeaders();
    return $response;
}

in view :

<img src=<?=$this->url('fourni',array('action' => 'image');?>class="img-rounded" alt="image" width="50" height="50">
2

There are 2 answers

7
Suman Karanjit On

Make sure the data folder is inside the public folder as well otherwise you will need to go up the directory "./../data/img/" for be able to access that image.

0
francisco viviers On

I was searching to do same... i just solved it like this:

At my phtml file:

<img src="<?php echo $this->basePath() .'/../data/img/logo.jpg';?>">

Hope is usefull.