Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] wywalanie katalogów z serwera
Forum PHP.pl > Forum > PHP
byczek
Witam mam taki oto kod do usówania userów z bazy ale problem w tym ze na serwerze zostaje katalog usera .Katalog nosi nazwe tak jak login danego usera co dopisac do tego kawałka tak aby i katalog poleciał smile.gif

oto moj kod

  1. <?php
  2. function usun_usera($id) {
  3. $r = mysql_fetch_assoc( mysql_query("SELECT login FROM owners WHERE id='{$id}'") );
  4. $login = $r['login'];
  5. @mysql_query("DELETE FROM owners WHERE id='{$id}'");
  6. if( file_exists('users/'.$login.'/') ) {
  7.  @unlink('users/'.$login.'/');
  8.  @exec('rm -rf /users/'.$login.'/');
  9.  
  10. }
  11. $this->_usun_users_form();
  12.  }
  13.  }
  14. ?>


Aha dodam ze na serwerze jest katalog danego usera a w nim są jeszcze dwa katalogi i kilka plików smile.gif
thornag
Musisz rekurencyjnie usunac wszystko co jest w katalogu zanim usuniesz sam katalog. Jesli chcesz to robic execkiem co w tym miejscu jest conajmniej dziwne to mozesz mu podac parametr ktory usunie wraz z zawartoscia. Execka nie uzywaj !?!

Napisz sobie funkcje ktora loopuje przez katalog i jesli trafia na katalog to uruchamia sama siebie.

  1. <?php
  2.  
  3.  
  4. #Pseudokod
  5.  
  6. function delete($sToDeletePath) {
  7. foreach(glob($sToDeletePath.'/*') as $sFilename) {
  8. if(!is_dir($sFilename)) {
  9. unlink($sFilename);
  10. } else {
  11. delete($sToDeletePath);
  12. }
  13. }
  14. unlink($sToDeletePath);
  15. }
  16. ?>


Edit: Nudzi mi sie troche w pracy to taki pseudo kod napisalem dla pomocy aarambo.gif
Luke_Star
czy delete() czasem nie działa tylko na niektórych wersjach PHP z doinstalowaną paczką? Bo to chyba nie jest standardowa funkcja
kwiateusz
Wyciągnięte z helpera w CodeIgniterze smile.gif

  1. <?php
  2. /**
  3.  * Delete Files
  4.  *
  5.  * Deletes all files contained in the supplied directory path.
  6.  * Files must be writable or owned by the system in order to be deleted.
  7.  * If the second parameter is set to TRUE, any directories contained
  8.  * within the supplied base directory will be nuked as well.
  9.  *
  10.  * @access public
  11.  * @param string path to file
  12.  * @param bool whether to delete any directories found in the path
  13.  * @return bool
  14.  */
  15. function delete_files($path, $del_dir = FALSE, $level = 0)
  16. {
  17. // Trim the trailing slash
  18. $path = preg_replace("|^(.+?)/*$|", "1", $path);
  19.  
  20. if ( ! $current_dir = @opendir($path))
  21. return;
  22.  
  23. while(FALSE !== ($filename = @readdir($current_dir)))
  24. {
  25. if ($filename != "." and $filename != "..")
  26. {
  27. if (is_dir($path.'/'.$filename))
  28. {
  29. $level++;
  30. delete_files($path.'/'.$filename, $del_dir, $level);
  31. }
  32. else
  33. {
  34. unlink($path.'/'.$filename);
  35. }
  36. }
  37. }
  38. @closedir($current_dir);
  39.  
  40. if ($del_dir == TRUE AND $level > 0)
  41. {
  42. @rmdir($path);
  43. }
  44. }
  45. ?>
eai
Jak wszyscy to i ja wrzuce swój kod:
  1. <?php
  2. function DeleteFromDirectory ($Dir)
  3. {
  4. $items = scandir($Dir);
  5.  
  6. if (!empty($items))
  7. {
  8. foreach($items as $file)
  9. {
  10. if(!is_dir($Dir . '/' . $file) && is_file($Dir . '/' .$file))
  11. {
  12.  unlink($Dir . '/' . $file);
  13. }
  14. if(is_dir($Dir . '/' . $file) && !is_file($Dir . '/' .$file))
  15. {
  16.  DeleteFromDirectory ($Dir . '/' . $file);
  17. }
  18. }
  19. }
  20. rmdir($Dir);
  21.  
  22. }
  23. ?>
byczek
Pieknie ładnie smile.gif ale coś nie zabardzo jestem bosem w tej dziedzinie sad.gif może by kto to mi dopisał do mojego kodu smile.gif byłbym wdzieczny smile.gif bo niechciał bym czegoś pomieszac i strona mi sie posypie sad.gif Baardzo bym prosił o pomoc smile.gif

Pozdrawiam

oto Kodd
  1. <?php
  2. function _usun_users_form() {
  3.  $r = mysql_fetch_assoc(mysql_query("SELECT COUNT(*) AS ile FROM owners"));
  4.  $ilosc = $r['ile'];
  5.  $start = (int)$_GET['p'];
  6.  $start *= 70;
  7. $q = mysql_query("SELECT * FROM owners ORDER BY owner,login ASC LIMIT $start,70");
  8. echo '<table width="400">';
  9. while( ($r=mysql_fetch_assoc($q)) != false ) {
  10.  if( is_array($r) ) { extract($r); }
  11.  echo '
  12.  <tr>
  13. <td>'.$login.'</td>
  14. <td>'.($owner?'tak':'nie').'</td>
  15. <td><a href="index.php?cmd=usun_usera&id='.$id.'">usuń</a></td>
  16.  </tr>
  17.  ';
  18. }
  19.  echo '<tr><td colspan="3">Strona: ';
  20.  for($i=1; $i<($ilosc/70); $i++) {
  21. echo '
  22.  <a href="?k=usun_users&p='.$i.'">'.$i.'</a>
  23. ';
  24.  }
  25.  echo '</td></tr>';
  26. echo '</table>';  
  27.  }
  28.  function usun_usera($id) {
  29. $r = mysql_fetch_assoc( mysql_query("SELECT login FROM owners WHERE id='{$id}'") );
  30. $login = $r['login'];
  31. @mysql_query("DELETE FROM owners WHERE id='{$id}'");
  32. if( file_exists('users/'.$login.'/') ) {
  33.  @unlink('users/'.$login.'/');
  34.  @exec('rm -rf /users/'.$login.'/');
  35.  
  36. }
  37. $this->_usun_users_form();
  38.  }
  39.  }
  40. ?>
eai
  1. <?php
  2.  
  3. function DeleteFromDirectory ( $Dir )
  4. {
  5. if ( is_dir( $Dir ) ) {
  6. $items = scandir( $Dir );
  7.  
  8. if ( !empty( $items ) ) {
  9. foreach( $items as $file ) {
  10. if ( !is_dir( $Dir . '/' . $file ) && is_file( $Dir . '/' . $file ) ) {
  11. unlink( $Dir . '/' . $file );
  12. } 
  13. if ( is_dir( $Dir . '/' . $file ) && !is_file( $Dir . '/' . $file ) ) {
  14. DeleteFromDirectory ( $Dir . '/' . $file );
  15. } 
  16. } 
  17. } 
  18. rmdir( $Dir );
  19. } 
  20. } 
  21.  
  22. function _usun_users_form()
  23. {
  24. $r = mysql_fetch_assoc( mysql_query( "SELECT COUNT(*) AS ile FROM owners" ) );
  25. $ilosc = $r['ile'];
  26. $start = ( int )$_GET['p'];
  27. $start *= 70;
  28. $q = mysql_query( "SELECT * FROM owners ORDER BY owner,login ASC LIMIT $start,70" );
  29. echo '<table width="400">';
  30. while ( ( $r = mysql_fetch_assoc( $q ) ) != false ) {
  31. if ( is_array( $r ) ) {
  32. extract( $r );
  33. } 
  34. echo '
  35.  <tr>
  36. <td>' . $login . '</td>
  37. <td>' . ( $owner?'tak':'nie' ) . '</td>
  38. <td><a href="index.php?cmd=usun_usera&id=' . $id . '">usuń</a></td>
  39.  </tr>
  40.  ';
  41. } 
  42. echo '<tr><td colspan="3">Strona: ';
  43. for( $i = 1; $i < ( $ilosc / 70 ); $i++ ) {
  44. echo '
  45.  <a href="?k=usun_users&p=' . $i . '">' . $i . '</a>
  46. ';
  47. } 
  48. echo '</td></tr>';
  49. echo '</table>';
  50. } 
  51.  
  52. function usun_usera( $id )
  53. {
  54. $r = mysql_fetch_assoc( mysql_query( "SELECT login FROM owners WHERE id='{$id}'" ) );
  55. $login = $r['login'];
  56. @mysql_query( "DELETE FROM owners WHERE id='{$id}'" );
  57. DeleteFromDirectory ( 'users/' . $login );
  58. $this->_usun_users_form();
  59. } 
  60.  
  61. ?>
byczek
Coś nie tak sad.gif wywala bład smile.gif

Fatal error: Call to undefined function: deletefromdirectory() in /home/KONTA/WWW/HOME/b/bambolo/_public_html/cmsek_include.php on line 401


Pomocy sad.gif tu 56 to linia 401 smile.gif

  1. <?php
  2. function DeleteFromDirectory ( $Dir )
  3. {
  4. if ( is_dir( $Dir ) ) {
  5. $items = scandir( $Dir );
  6.  
  7. if ( !empty( $items ) ) {
  8. foreach( $items as $file ) {
  9. if ( !is_dir( $Dir . '/' . $file ) && is_file( $Dir . '/' . $file ) ) {
  10. unlink( $Dir . '/' . $file );
  11. } 
  12. if ( is_dir( $Dir . '/' . $file ) && !is_file( $Dir . '/' . $file ) ) {
  13. DeleteFromDirectory ( $Dir . '/' . $file );
  14. } 
  15. } 
  16. } 
  17. rmdir( $Dir );
  18. } 
  19. } 
  20.  
  21. function _usun_users_form()
  22. {
  23. $r = mysql_fetch_assoc( mysql_query( "SELECT COUNT(*) AS ile FROM owners" ) );
  24. $ilosc = $r['ile'];
  25. $start = ( int )$_GET['p'];
  26. $start *= 70;
  27. $q = mysql_query( "SELECT * FROM owners ORDER BY owner,login ASC LIMIT $start,70" );
  28. echo '<table width="400">';
  29. while ( ( $r = mysql_fetch_assoc( $q ) ) != false ) {
  30. if ( is_array( $r ) ) {
  31. extract( $r );
  32. } 
  33. echo '
  34.  <tr>
  35. <td>' . $login . '</td>
  36. <td>' . ( $owner?'tak':'nie' ) . '</td>
  37. <td><a href="index.php?cmd=usun_usera&id=' . $id . '">usuń</a></td>
  38.  </tr>
  39.  ';
  40. } 
  41. echo '<tr><td colspan="3">Strona: ';
  42. for( $i = 1; $i < ( $ilosc / 70 ); $i++ ) {
  43. echo '
  44.  <a href="?k=usun_users&p=' . $i . '">' . $i . '</a>
  45. ';
  46. } 
  47. echo '</td></tr>';
  48. echo '</table>';
  49. } 
  50.  
  51. function usun_usera( $id )
  52. {
  53. $r = mysql_fetch_assoc( mysql_query( "SELECT login FROM owners WHERE id='{$id}'" ) );
  54. $login = $r['login'];
  55. @mysql_query( "DELETE FROM owners WHERE id='{$id}'" );
  56.  DeleteFromDirectory ( 'users/' . $login );
  57. $this->_usun_users_form();
  58. } 
  59.  }
  60. ?>


A tak wywglada to na serwerze



Nikt nie pomoze sad.gif pliss smile.gif sam raczej nie dam rady sad.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.