Tuesday, March 6, 2012

Displaying images using MediaView based Controller - Help!

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���������������������������������

[COLOR=red][B]Can you tell how to use this MediaView in a controller
and display images?
[/B][/COLOR]

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

Thanks
-BC

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate