カテゴリを作成するときに画像フォルダを作成できるので、そこに画像をアップロードできます。
カテゴリを削除するときに、そのフォルダーを削除したいと思います。
フォルダーを作成するためのコードは次のとおりで、うまく機能します。
function create(){
if ($this->input->post('name')){
$this->MCats->addCategory();
$folder = $this->input->post('name');
$folder = strtolower($folder);
$folder = str_replace(" ", "_", $folder);
$folder = 'images/'.$folder;
$this->_create_path($folder);
...
...
}
function _create_path($folder)
{
// create dir if not exists
$folder = explode( "/" , $folder );
$mkfolder = "";
//sets the complete directory path
for( $i=0 ; isset( $folder[$i] ) ; $i++ )
{
$mkfolder .= $folder[$i] . '/';
if(!is_dir($mkfolder )) mkdir("$mkfolder");
}
}
そして、私は次のコードを思いつきます。しかし、画像フォルダーを削除しないように rmdir を使用する方法がわかりません。images フォルダの子だけを削除したい。
function delete($id){
$cat = $this->MCats->getCategory($id);
// This will pull the name of category name.
$catname = $cat['name'];
$catname = strtolower($catname);
$catname = str_replace(" ", "_", $catname);
$catname = 'images/'.$catname;
$this->_remove_path($catname);
...
...
}
function _remove_path($folder)
{
}
この後どのように進めばよいかわかりません。
誰か提案をお願いできますか?