我有以下代码在 cakephp 中上传文件
class UsersController extends AppController {
var $name = 'Users';
function index() {
$this->set('users', $this->User->find('all'));
}
function add() {
if (!empty($this->data)) {
if ($this->User->save($this->data)) {
$this->Session->setFlash('Your user data has been saved.');
$this->redirect(array('action' => 'index'));
}
$this->User->create();
if ($this->uploads() && $this->User->save($this->data)) {
$this->Session->setFlash(_('Upload saved', true));
} else {
$this->Session->setFlash(_('Upload not saved.Please try again', true));
}
}
}
function uploads() {
$uploads_dir = '/uploads';
$users = $this->request->data['Upload']['file'];
if ($users['error'] === UPLOAD_ERR_OK) {
if (move_uploaded_file($users['User']['file'], $uploads_dir)) {
$this->User->saveAll($this->data);
return true;
}
}
return false;
}
function edit($id = null) {
$this->User->id = $id;
if (empty($this->data)) {
$this->data = $this->User->read();
} else {
if ($this->User->save($this->data)) {
$this->Session->setFlash('Your user details has been updated.');
$this->redirect(array('action' => 'index'));
}
}
}
function delete($id) {
$this->User->delete($id);
$this->Session->setFlash('This user has been deleted.');
$this->redirect(array('action' => 'index'));
}
}
当我尝试上传时,文件正在上传,但我需要在显示每个 .jpeg 的超链接时查看上传的文件,但我收到错误消息
" 在此服务器上找不到请求的地址 '/Users/app/webroot/index.php/uploads'。"
另外请帮助我如何将上传的图像存储在另一个文件夹中
PS:: 代码应该纯粹在 CakePHP 中
请帮助,在此先感谢