Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to display image from webroot folder using the image pathname in cakephp?
    primarykey
    data
    text
    <p>Hai i am new to the cakephp.I have create one sample form having two fields name and image file.I was able to save image name and uername in database table and save the image in webroot folder.Now i want to retrieve image using particular id.How can i retrieve the image from the webroot folder using the particular user id?.Please help me to improve my knowledge in cakephp.</p> <p>Add.ctp</p> <pre><code>&lt;?php echo $this-&gt;Form-&gt;create('User', array('controller' =&gt; 'users', 'action' =&gt; 'add','type' =&gt; 'file','enctype' =&gt; 'multipart/form-data')); echo $this-&gt;Form-&gt;input('name'); echo $this-&gt;Form-&gt;input('image', array('type' =&gt; 'file')); echo $this-&gt;Form-&gt;end('Submit'); ?&gt; </code></pre> <p>UserController.php</p> <pre><code>&lt;?php class UsersController extends AppController { public $helpers = array('Html', 'Form'); public function beforeFilter() { parent::beforeFilter(); $this-&gt;Auth-&gt;allow('add','retrieve'); } public function retrieve() { $this-&gt;loadModel('User'); $ret = $this-&gt;User-&gt;find('all'); $this-&gt;set('retrieve', $ret); } public function add() { if ($this-&gt;request-&gt;is('post')) { $this-&gt;User-&gt;create(); $this-&gt;loadModel('User'); $id = $this-&gt;request-&gt;data['User']['id']; $pathname = $this-&gt;request-&gt;data['User']['image']['tmp_name']; $filename = $this-&gt;request-&gt;data['User']['image']['name']; $this-&gt;request-&gt;data['User']['image'] = $filename; if($this-&gt;User-&gt;save($this-&gt;request-&gt;data)) { move_uploaded_file($pathname, $_SERVER['DOCUMENT_ROOT'] . '/cakephp_image /app/webroot/files/' . $filename); $this-&gt;Session-&gt;setFlash(__('The Image has been saved')); return $this-&gt;redirect(array('controller' =&gt; 'users', 'action' =&gt; 'retrieve')); } else { $this-&gt;Session-&gt;setFlash(__('The Image could not be saved. Please, try again.')); } } } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload