您好我正在尝试创建一个文件上传系统,我可以在其中上传文件,它将文件名更改为已上传到表中的 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 表。
我不明白为什么这个函数 $this->Upload->id 不适用于文件重命名?如果我把它放在语音标记中,那么它会将文件重命名为“$this->Upload->id.mp4”,但如果那是保存信息的字段,我希望它更像 114.mp4。有人有什么想法吗?
提前致谢