use*_*593 4 php upload codeigniter
我使用Codeigniter的Upload Class将图像上传到项目中的文件夹.在数据库中我只存储上传图像后生成的url,所以当我想删除db中的一行时我还需要删除图像.我怎么能在codeigniter中做到这一点?
我将很感激你的答案.
tim*_*son 11
您可以uploads使用此deleteFiles()功能删除给定路径中的所有文件,例如在文件夹中,该功能可能位于您的某个模型中:
$path = $_SERVER['DOCUMENT_ROOT'].'/uploads/';
function deleteFiles($path){
$files = glob($path.'*'); // get all file names
foreach($files as $file){ // iterate files
if(is_file($file))
unlink($file); // delete file
//echo $file.'file deleted';
}
}
Run Code Online (Sandbox Code Playgroud)