Powered by Invision Power Board



  Reply to this topicStart new topicStart Poll

> Display Image from MediaView based Controller, Display Image from MediaView based Contr
bluesclues9
Posted: Mar 6 2012, 02:54 PM
Quote Post


Member
**

Group: Members
Posts: 11
Member No.: 2721
Joined: 3-March 11



Hi
I am trying to display image retrieved using MediaView based Controller.

My controller looks like this:

CONTROLLER:

function getImg(){
$this->autoLayout = false;
if($this->RequestHandler->isAjax()){
Configure::write('debug', 0);
}
$this->view = 'Media';
header('Content-type: $type');
$params = array('id' => '175209_20.png',
'name' => 'user_img_name',
'download' => false,
'extension' => 'png', // must be lower case
'path' => APP.WEBROOT_DIR . DS . 'files\upload' . DS
);
$this->set($params);
}

I hardcoded image name here just to see if this works atleast.

VIEW:

<script>
$.ajax({
url: baseAction+'images/getImg',
data: 'id='+id,
success: function(msg){
$('#preview-img').html('<img src="data:image/png;base64,' + msg + '" ></img>');
}
}).error(function(){
alert('ajax error!'); });

</script>


the image is displayed as:

<img src="�PNG���������������������������������

Can you tell how to use this MediaView in a controller and display images?


I am very close I think but this is killing me.

Thanks
-BC
PMEmail Poster
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Disclaimer:
This forum is in no way affiliated with the Cake Software Foundation
The CakePHP name and icon is a trademark of the Cake Software Foundation


Lo-Fi Version