...so just to clarify, the order of when you define the function versus where you define the variable doesn't matter really matter. This problem has to do with the "scope" of the $cat_name variable.
I'll explain, but first, an example of the very simple solution would be:
function remove_cat_folder($path) {
global $cat_name; // NEW LINE ADDED
$ok = 1;
if (@is_dir($path)) {
$handle = opendir($path);
while ($file = @readdir($handle)) {
if ($file != "." && $file != "..") {
$ok = (!remove_cat_folder($path."/".$file)) ? 0 : $ok;
}
}
closedir($handle);
$ok = (!rmdir($path)) ? 0 : $ok;
}
else {
$ok = (!unlink($path)) ? 0 : $ok;
}
unlink("/www/tia/pictures/about/$cat_name.htm");
return $ok;
}
Notice the new first line inside the function definition? That makes this function be able to "see" the variable named $cat_name.
Normal variables that are defined outside of the function can not be "seen" by code that runs inside the function unless you insert a line like that inside the function before the code that needs to make use of the variable.
An alternative to dealing with the variable scope issue would be to add a second parameter to the function that passed the value of the $cat_name variable into the function like this:
function remove_cat_folder($path, $the_cat) {
$ok = 1;
if (@is_dir($path)) {
$handle = opendir($path);
while ($file = @readdir($handle)) {
if ($file != "." && $file != "..") {
$ok = (!remove_cat_folder($path."/".$file)) ? 0 : $ok;
}
}
closedir($handle);
$ok = (!rmdir($path)) ? 0 : $ok;
}
else {
$ok = (!unlink($path)) ? 0 : $ok;
}
unlink("/www/tia/pictures/about/$the_cat.htm");
return $ok;
}
So, then you would need to call the function like this:
//assumes that the $path variable is the variable you are using to store the path name.
remove_cat_folder($path, $cat_name);
I hope that helps more than it confuses.
-skyeflye