Why this function is not working? PHP -


this original function , works perfectly...

    function delete_directory($dirname) {    if (is_dir($dirname))     $dir_handle = opendir($dirname);      if (!$dir_handle)       return false;    while ($file = readdir($dir_handle)) {      if ($file != "." && $file != "..") {       if (!is_dir($dirname."/".$file))                    unlink($dirname."/".$file);               else                    delete_directory($dirname.'/'.$file);          }    }    closedir($dir_handle);    rmdir($dirname);    return true;   } 

i tried version curly braces , different names not working , i'm not sure problem is

    function borrar_directorio ($carpeta) {    if (is_dir($carpeta)) {      $abrir_directorio = opendir($carpeta);      if (!$abrir_directorio) {        return false;     }   }    while ($archivo = readdir($abrir_directorio)) {        if ($archivo != "." && $archivo != "..") {          if (!is_dir($carpeta."/".$archivo)) {           unlink($carpeta."/".$achivo);          } else {            borrar_directorio($carpeta.'/'.$archivo);         }       }     }    closedir($abrir_directorio);   rmdir($carpeta);   return true; } 

what i'm missing? hope can me, in advance

one possible problem in how have written if folder not exist or can not opened due permission restrictions or filesystem errors, while loop still run.

here's how original script should written using curly-braces

  if(is_dir($carpeta))   {     $abrir_directorio = opendir($carpeta);   }   if(!$abrir_directorio)   {     return false;   }    while($archivo = readdir($abrir_directorio))   { ... 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -