| CakePHP Official Site · Rules and Regulations |
Help
Search
Members
Calendar
Shoutbox
|
| Welcome Guest ( Log In | Register ) | Resend Validation Email |
![]() ![]() ![]() |
| bluesclues9 |
Posted: Mar 6 2012, 02:54 PM
|
|
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 |
![]() |
![]() ![]() ![]() |