I have a problem when my uploads folder has been deleted after I delete directory in that uploads folder with this code below
function delete_files($target,$target_thumb) {
if(is_dir($target)){
$files = glob( $target . '*', GLOB_MARK );
foreach( $files as $file )
{
delete_files( $file );
}
rmdir( $target );
} elseif(is_file($target)) {
unlink( $target );
}
if(is_dir($target_thumb)){
$files = glob( $target_thumb . '*', GLOB_MARK );
foreach( $files as $file )
{
delete_files( $file );
}
rmdir( $target_thumb );
} elseif(is_file($target_thumb)) {
unlink( $target_thumb );
}
}
All I want to do is to delete category and files in it from uploads folder.. What it does, it deletes all uploads folder with all files in it.. Have no idea why. Any suggestions would be helpful.
EDIT 1:
I see.. $target
shows as "../uploads/"
after I echo it..
$cat_id = $_GET['cat_id'];
$cat_data = data_cat($cat_id,'name');
if (empty($cat_id)){
header("Location: categories.php");
exit;
}
if (isset($_GET['cat_id'])){
$cat_id = $_GET['cat_id'];
$query = mysql_query("DELETE FROM cattegories WHERE cat_id = $cat_id");
$target = ('../uploads/'.$cat_data['name']);
$target_thumb = ('../uploads/thumbs/'.$cat_data['name']);
delete_cat($cat_id);
delete_files($target,$target_thumb);
header("Location: categories.php");
exit();
}
It seems that my function cant grab the name of the category..
EDIT 2:
Thats my data_cat
function:
function data_cat($cat_id){
$cat_id = (int)$cat_id;
$args = func_get_args();
unset($args[0]);
$fields = '`'.implode('`,`', $args).'`';
$query = mysql_query("SELECT $fields FROM `cattegories` WHERE `cat_id` = $cat_id");
$query_result = mysql_fetch_assoc($query);
foreach ($args as $field){
$args[$field] = $query_result[$field];
}
return $args;
}
P.S. Name cattegories is correct, I just made a mistake in db naming it.