Tuesday, February 11, 2014

File Upload Err..

Dear group members i facing one error in document uploading process..
While inserting file into database

Note:
docName is in array even i set like this 

$this->data['Document']['docName'] = $filename;

Controller page:
~~~~~~~~~~~

public function add(){



if (!empty($this->data)) {
$this->Document->create();
if ($this->uploadFile() && $this->Document->save($this->request->data)) {

$this->Session->setFlash(__('The upload has been saved', true));
$this->redirect(array('action' => 'add'));
} else {

$this->Session->setFlash(__('The upload could not be saved. Please, try again.', true));
}
}
/*$users = $this->documents->User->find('list');
$users = $this->documents->User->find('list');
$this->set(compact('users', 'users'));*/




}

public function uploadFile() {

// pr($this->request->data) ;
// echo $this->request->data['Document']['docName']['name']; exit;
$file = $this->request->data['Document']['docName'];
if ($file['error'] === UPLOAD_ERR_OK) {
$id = String::uuid();
$filename = basename($this->request->data['Document']['docName']['name']);
// echo $filename;exit;
if (move_uploaded_file($file['tmp_name'], APP.'uploads'.DS.$id)) {


$this->data['Document']['docName'] = $filename;

return true;
}
}
return false;
}

/*------*/

view/add.ctp
~~~~~~~~~~

<?php
echo $this->Form->create('Document', array('type' => 'file'));
echo $this->Form->input('user', array('type' => 'hidden', 'value' => '1'));
echo $this->Form->input('docName', array('type' => 'file'));
echo $this->Form->end('Submit', true);
?>

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: