function delete($id) { // delete button is hidden in the page, but // check if parentid is not 0 $cate = $this->MCats->getCategory($id); $parentid = $cate['parentid']; if (!$parentid == 0) { $cat = $this->MCats->getCategory($id); $string = $cat['name']; $catname = createdirname($string); $catname = 'assets/images/' . $catname; recursive_remove_directory($catname, $empty = FALSE); $orphans = $this->MCats->checkOrphans($id); if (count($orphans)) { $this->session->set_userdata('orphans', $orphans); redirect('category/admin/reassign/' . $id, 'refresh'); } else { $this->MCats->deleteCategory($id); flashMsg('success', $this->lang->line('userlib_category_deleted')); redirect('category/admin/index', 'refresh'); } } else { $this->MCats->deleteCategory($id); flashMsg('success', $this->lang->line('userlib_category_deleted')); redirect('category/admin/index', 'refresh'); } }
function _uploadFile() { $data = array( 'name' => db_clean($_POST['name']), 'shortdesc' => db_clean($_POST['shortdesc']), 'longdesc' => db_clean($_POST['longdesc'],5000), 'status' => db_clean($_POST['status'],8), 'class' => db_clean($_POST['class'],30), 'grouping' => db_clean($_POST['grouping'],16), 'category_id' => id_clean($_POST['category_id']), 'featured' => db_clean($_POST['featured'],20), 'price' => db_clean($_POST['price'],16), 'other_feature' => db_clean($_POST['other_feature'],20) ); $catname = array(); $category_id = $data['category_id']; $catname = $this->MCats->getCategoryNamebyProduct($category_id); foreach ($catname as $key => $name) { $foldername = createdirname($name); } if ($_FILES) { $config['upload_path'] = './assets/images/'.$foldername.'/'; $config['allowed_types'] = 'gif|jpg|png|ico'; $config['max_size'] = '400'; $config['remove_spaces'] = true; $config['overwrite'] = true; $config['max_width'] = '0'; $config['max_height'] = '0'; // Here we are loading CI's file uploading class $this->load->library('upload', $config); if (strlen($_FILES['image']['name'])) { if(!$this->upload->do_upload('image')) { $this->upload->display_errors(); exit("unable to open file ($foldername). The folder does not exist. You need to create a category first."); } $image = $this->upload->data(); if ($image['file_name']) { $data['image'] = "assets/images/".$foldername."/".$image['file_name']; } } $config['upload_path'] = './assets/images/'.$foldername.'/thumbnails/'; $config['allowed_types'] = 'gif|jpg|png|ico'; $config['max_size'] = '200'; $config['remove_spaces'] = true; $config['overwrite'] = true; $config['max_width'] = '0'; $config['max_height'] = '0'; //initialize otherwise thumb will take the first one $this->upload->initialize($config); if (strlen($_FILES['thumbnail']['name'])) { if(!$this->upload->do_upload('thumbnail')) { $this->upload->display_errors(); exit("unable to open a thumbnail folder in the folder ($foldername). You need to contact Admin."); } $thumb = $this->upload->data(); if ($thumb['file_name']) { $data['thumbnail'] = "assets/images/".$foldername."/thumbnails/".$thumb['file_name']; } } } return $data; }