使用codeigniter删除目录 [英] Removing directory using codeigniter

查看:121
本文介绍了使用codeigniter删除目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的codeigniter所以请原谅我,我想让codeigniter删除一个基本文件夹(我不知道什么是正确的术语,它是我把我上传的文件和它的位置在我的codeigniter项目的根)。因为我是新的codeigniter,我不知道如何使用codeigniter api中的文件助手参考。我希望有人能帮助我这个。

I'm new to codeigniter so please forgive me, I am trying to make codeigniter delete a base folder (I don't know what the right term is, it's the folder where I put my uploaded files and its located in the root of my codeigniter project). Since I am new to codeigniter, I don't have any idea on how to make use of the File Helper reference in the codeigniter api. I hope someone can help me with this.

此外,我想要删除的功能还需要删除其所有内容,因此为空或不是,该文件夹被删除。我猜,它会使用递归类型的删除...我不太确定。

Furthermore, the delete function I am trying to make needs to delete also all of its contents, so empty or not, the folder gets deleted. I'm guessing, it would use a recursive type of deletion...I'm not so sure at all.

推荐答案

您可以使用 delete_files 功能删除所有文件

You can delete all files using delete_files function

$path=$this->config->base_url().'dir_name';
$this->load->helper("file"); // load the helper
delete_files($path, true); // delete all files/folders

上述代码将从给定路径中删除所有文件和文件夹,如果一旦目录为空,您就可以使用 rmdir 删除一个空目录,例如

Above code will delete all files and folders from the given path and if once the directory is empty then you can use rmdir which deletes an empty directory, like

rmdir($path);

文件夹应该允许相关权限,这意味着文件/文件夹必须是可写的,要删除的订单。

The folder should permit relevant permissions, which means files/folder must be writable or owned by the system in order to be deleted.

这篇关于使用codeigniter删除目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆