I have a field named 'path' in my db that has the exact same number(path) as its counterpart folder under cart/zips.
So my path in my db might be '23423423', and in cart/zips you'd have the folder 23423423. There is a corresponding session with each 'path' row. Based on the session, I want to retrieve the path name and delete its counterpart folder name (and all it's sub-files it may contain). The delete_all_from_dir function below is deleting the whole zips folder when I only want it to delete the path folder below it and its contents.
<?
if(isset($_GET['del'])){
include ("cart/includes/db.conf.php");
include ("cart/includes/connect.inc.php");
$query1="Select path from catalog where session='$_GET[del]'";
$result = mysql_query($query1,$db); //total results
while ($row = mysql_fetch_array ($result)){
$path = $row['path'];
$dir_del = "cart/zips/$path";
function delete_all_from_dir($Dir){
// delete everything in the directory
if($handle = @opendir($Dir)) {
while (($file = readdir($handle)) !== false) {
if($file == "." || $file == "..") { continue; }
if(is_dir($Dir.$file)){ // call self for this directory
delete_all_from_dir($Dir."/".$file."/");
chmod($Dir."/".$file, 0777);
rmdir($Dir."/".$file);
}else {
chmod($Dir."/".$file, 0777);
unlink($Dir."/".$file); // remove this file
}
}
}
@closedir($handle);
}
delete_all_from_dir($dir_del);
rmdir($dir_del);
}
$query2="delete from catalog where session='$_GET[del]'";
$res=mysql_query($query2) or die("SQL: $query2<br />\nError: ".mysql_error());
echo "<script type=\"text/javascript\">window.location = \"manage.php?action=expiredview\";</script>";
}
?>