For some reason my code is not working to create the proper directories to add the images so the images of course can not be called on my view products pages or my view categories section. Any suggestions on why the directories are not be created. I would greatly appreciate the help and sorry for the length of the code I'm getting 0 errors it just isn't working at all.
<?php
//Bein addImage() function
function addimage($cat_father_id, $database_trustinme, $trustinme, $cat_name, $tmp_name, $image_name, $serverPath){
$cat_name = str_replace(' ', '', $cat_name);
//Find's if there is a Father ID for the Category affects if there needs to be a sub directory or a primary
//Directory created.
if(isset($cat_father_id)){
$selectSQL = "SELECT cat_name FROM category WHERE cat_id = '$cat_father_id'";
mysql_select_db($database_trustinme, $trustinme);
$Result1 = mysql_query($selectSQL, $trustinme) or die(mysql_error());
while($row = mysql_fetch_array($Result1)) {
$cat_father_name = str_replace(' ', '', $row['cat_name']);
}
//Directory Path
$top_dir = $serverPath.'images/'.$cat_father_name;
//Directory Path
$cat_dir = $top_dir.'/'.$cat_name;
//Creates a direcotry for the Father ID if set.
if(is_dir($top_dir)){
$error .= "Directory already exists: ".$top_dir."<br>";
} else {
mkdir($top_dir, 0777);
}
//Creates a direcotry for the cat just added.
if(is_dir($cat_dir)){
$error .= "Directory already exits: ".$cat_dir."<br>";
} else{
mkdir($cat_dir, 0777);
}
} else {
//Directory Path
$cat_dir = $serverPath.'images/'.$cat_name;
//Creates a directory for the category just added
if(is_dir($cat_dir)){
$error .= "Directory already exists: ".$cat_dir."<br>";
} else {
mkdir($cat_dir, 0777);
}
}
session_start();
$_SESSION["cat_dir"] = $cat_dir;
//Moving Uploaded images temporary file.
move_uploaded_file($tmp_name, "$cat_dir/".$image_name)or die("Couldn't copy");
mysql_free_result($Result1);
}//End addImage() function
?>