Home > Article > Backend Development > How to delete data and files together in tp5 (code)
The content of this article is about how tp5 can delete data and files together (code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
unlink is a method of deleting files, just pass in the file path
public function delete() { $article_id = input('article_id'); if (intval($article_id) <= 0) { $this->error("参数错误!"); } //删除文件 $article_info = DB::name('Article')->where(array('article_id' => $article_id))->find(); $path = ROOT_PATH . 'Uploads' . DS . $article_info['article_content']; if (file_exists($path)) { unlink($path);//删除文件 }; //删除数据库 $result = DB::name('Article')->where(array('article_id' => $article_id))->delete(); if ($result) { $this->success("成功删除" . $result . "个材料", 'Article/index', '', 1); } else { $this->error("删除失败!"); } }
Related recommendations:
php Delete data table and delete database
PHP Delete the first and last two lines of the txt file.
The above is the detailed content of How to delete data and files together in tp5 (code). For more information, please follow other related articles on the PHP Chinese website!