0
嗨我試圖創建一個文件上傳系統,我可以上傳一個文件,它會將文件名更改爲上傳到表的MYSQL ID。 這是我的代碼...CakePHP 2.0文件上傳不起作用
function add() {
if (!empty($this->data)) {
$this->Upload->create();
if ($this->uploadFile() && $this->Upload->save($this->data)) {
$this->Session->setFlash(__('<p class="uploadflash">The upload has been saved</p>', true));
$this->redirect(array('action' => 'add'));
} else {
$this->Session->setFlash(__('<p class="uploadflash">The upload could not be saved. Please, try again.</p>', true));
}
}
}
function uploadFile() {
$file = $this->request->data['Upload']['file'];
if ($file['error'] === UPLOAD_ERR_OK) {
if (move_uploaded_file($file['tmp_name'], APP.'webroot/files/uploads'.DS.$this->Upload->id.'.mp4')) {
$this->Upload->save($this->data);
return true;
}
}
return false;
}
但是文件沒有被上傳到了目錄,但該信息被上傳到SQL田部。
我不明白爲什麼這個函數$ this-> Upload-> id不適用於文件重命名? 如果我把它放在語音標記中,那麼它將文件重命名爲「$ this-> Upload-> id.mp4」,但是我希望它更像114.mp4,如果那是保存信息的字段。 有人有什麼想法嗎?
在此先感謝
非常感謝你這工作,它只是一種先保存然後重命名的情況。非常感激! – 001221 2012-03-06 13:53:43