![](/img/trans.png)
[英]Problems saving title/description with cakephp2.0 file upload plug in
[英]CakePHP 2.0 file upload not working
嗨,我正在嘗試創建一個文件上傳系統,我可以在其中上傳文件,它將文件名更改為已上傳到表中的MYSQL ID。 這是我的代碼...
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 tabe。
我看不到為什么此功能$ this-> Upload-> id對文件重命名不起作用? 如果我將其放在語音標記中,則它將文件重命名為“ $ this-> Upload-> id.mp4”,但如果那是保存信息的字段,則我希望它更類似於114.mp4。 有人有什么想法嗎?
提前致謝
您需要先保存。 $ this-> Upload-> id在您的情況下為空。
為了您的利益:$ this-> Upload-> create(); 清除$ this-> Upload-> id
也可以看看:
http://api20.cakephp.org/class/model#method-Modelcreate http://api20.cakephp.org/view_source/model#line-1381
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.