The script I'm making is for a private gallery for a photography company. I need to add a gallery folder for individual users, but also need to delete that folder when the user is removed from the db.  I can make a folder using this code: <?php  include "../includes/db.php"; //include db config file  //post data from the form  $username= mysql_real_escape_string($_POST['username']);  $password= md5($_POST['password']); $gallery= mysql_real_escape_string($_POST['username']); //start insert  mysql_query("INSERT INTO `p_users` VALUES ( '$id', '$username', '$password', '$gallery') "); //done  echo "<font color=green>Success:</font> The user was added to the database!<br><br><font color=red><b>YOU WILL BE REDIRECTED SHORTLY...</font></b> //redirect <meta http-equiv='REFRESH' content='3;url=http://www.***'>"; //make the directory  mkdir("../images/usergalleries/$username", 0700); ?> PHP:   But I'm having  difficulty removing the folder when the user is removed: <?php $username = $_POST['username']; include "../includes/db.php"; mysql_query("DELETE FROM p_users WHERE username = '$username'"); echo "<font color=green>Success:</font> The user was removed from the database!<br><br><font color=red><b>YOU WILL BE REDIRECTED SHORTLY...</font></b> <meta http-equiv='REFRESH' content='3;url=http://www***'>";  if (!is_dir('../images/usergalleries/$username/')) { mkdir('../images/usergalleries/$username/'); } rmdir('../images/usergalleries/$username/'); PHP: ?> Could somebody help? If you reply with a script, could you please let me know what's happening with the script so I can understand it. Thanks!Â
The folder must be empty before being deleted. Maybe this will work (not tested). if (is_dir('../images/usergalleries/$username/')) { $directory = '../images/usergalleries/$username/'; $handler = opendir($directory); while ($file = readdir($handler)) {//delete all files if ($file != "." && $file != "..") { unlink($directory.$file); } } closedir($handler); rmdir($directory); } PHP:
Nope, nada, nothing. Doesn't output an error but also doesn't remove the directory which is already empty.
Ah good point, I'm sure I'm creating the directory by CHMOD 0700. Edit to add: Nope, changed it to 0777 and still doesn't delete it.Â