cakephp - Not able upload filename into db, in uploading concepts -
in userscontroller.php
public function uploadfile() { $filename = ''; if ($this->request->is('post')) { $uploaddata = $this->data['uploadfile']['image']; if ( $uploaddata['size'] == 0 || $uploaddata['error'] !== 0) { return false; } $filename = basename($uploaddata['name']); if ($this->user->save($filename)) { $this->session->setflash(__('your imagename has been saved.')); } $uploadfolder = www_root. 'files'; $filename = time() .'_'. $filename; $uploadpath = $uploadfolder . ds . $filename; if( !file_exists($uploadfolder) ){ mkdir($uploadfolder); } if (!move_uploaded_file($uploaddata['tmp_name'], $uploadpath)) { //$this->set('pdf_path', $filename); return false; } } } }
and in uploadfile.ctp
<?php echo $this->form->create('uploadfile', array( 'type' => 'file')); echo $this->form->input('image', array('type' => 'file','label' => 'pdf')); echo $this->form->end('upload file'); ?>
in db have table name "image" along other fields. i'm not able upload file name db.
if have table name called 'image', should related user model. $this->user->save($filename) needs @ least table field called 'filename' in user table , needs assigned user via $this->user->id = $user_id;
if image table has image model related user model, read book's chapter 'saving related model data' http://book.cakephp.org/2.0/en/models/saving-your-data.html#saving-related-model-data-hasone-hasmany-belongsto
Comments
Post a Comment