我正在开发一个 cakephp 2.x ...我有一个表单,我从用户那里获取文件,然后我将文件保存到app/uploads/userid文件夹并将路径保存到 db 中...我是成功获取文件并将其显示给用户,但现在问题出在下载过程中。我的意思是每当用户单击文件链接时,它都会将用户重定向到某个未知链接
这是我的代码
公共函数上传文件(){
if ($this->request->isPost()){
$this->loadModel('Audio');
$file = $this->request->data['Audio']['file'];
$idUser = $this->Auth->user('idUser');
if ($file['error'] === UPLOAD_ERR_OK) {
$id = String::uuid();
$name =$file['name'];
$folder_url = APP.'uploads/'.$idUser;
if(!is_dir($folder_url)) {
mkdir($folder_url);
}
move_uploaded_file($file['tmp_name'], $folder_url.DS.$name);
$this->request->data['Audio']['User_id'] = $idUser;
$this->request->data['Audio']['filename'] = $file['name'];
$this->request->data['Audio']['filesize'] = $file['size'];
$this->request->data['Audio']['filemime'] = $file['type'];
$this->Audio->save($this->request->data);
return true;
}
}
return false;
}
public function showfile(){
$this->loadModel('Audio');
$record = $this->Audio->find('first', array('conditions' => array('User_id' => $this->Auth->user('idUser'))));
$this->set('file', $record);
}
在我的查看页面上
<?php echo $this->Html->link($file['Audio']['filename'], APP . DS . 'uploads' . DS . $file['Audio']['User_id'] . DS . $file['Audio']['filename'] . DS . $file['Audio']['filemime']);?>
这是点击链接后的网址
/localhost/cakephp/media/C:/xampp/htdocs/cakephp/app//uploads/23/1011029_10152615392142588_1926259269_n.jpg/image/jpeg
我已经尝试了所有方法以使其正常工作。对我来说没有任何效果..请我需要帮助..