Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> php i usuwanie folderów, problem :/
Edd_s
post 7.04.2005, 21:55:20
Post #1





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 5.04.2005

Ostrzeżenie: (0%)
-----


w php jest taka funkcjia: rmdir(nazwa) jest fajna bo usuwa katalog na serwerze o podanej nazwie, ale katalog musi być pusty, no właśnie w tym problem, czy jest jakaś funkcja kasująca folder z zawartością czy są jakieś inne sposoby albo ktoś ma jakiś pomysłquestionmark.gif dry.gif
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
Spirit86
post 7.04.2005, 22:09:45
Post #2





Grupa: Zarejestrowani
Postów: 607
Pomógł: 23
Dołączył: 8.09.2004
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


unlink" title="Zobacz w manualu PHP" target="_manual


--------------------
Audio: Metallica, Soil, RHCP, OffSpring, Green Day, "Retro", Gorillaz, Disturbed, Coma
DB: MySQL 4.1 | php: 4.4.3 Pomogłem Ci? Wciśnij przycisk POMÓGŁ.
Go to the top of the page
+Quote Post
ebe
post 7.04.2005, 22:16:50
Post #3





Grupa: Zarejestrowani
Postów: 150
Pomógł: 1
Dołączył: 23.01.2004

Ostrzeżenie: (0%)
-----


unlink nie skasuje katalogu z plikami.

Do autora topicu, czasem bardzo owocne jest czytanie komentarzy w manualu. Jest tam piękny przykład, nie jestem jego autorem:


  1. <?
  2. function rmdirRecursive($path,$followLinks=false) {
  3.  
  4.  $dir = opendir($path);
  5.  while ( $entry = readdir($dir) ) {
  6.  
  7.  if ( is_file( &#092;"$path/$entry\" ) || ((!$followLinks) && is_link(\"$path/$entry\")) ) {
  8.  echo ( &#092;"unlink $path/$entry;n\" );
  9.  // Uncomment when happy!
  10.  //unlink( \"$path/$entry\" );
  11.  } elseif ( is_dir( &#092;"$path/$entry\" ) && $entry!='.' && $entry!='..' ) {
  12.  rmdirRecursive( &#092;"$path/$entry\" );
  13.  }
  14.  }
  15.  closedir($dir);
  16.  echo &#092;"rmdir $path;n\";
  17.  // Uncomment when happy!
  18.  // return rmdir($path);
  19. }
  20. ?>


Ten post edytował ebe 7.04.2005, 22:17:15


--------------------
Słyszałem, że macie tutaj jakieś takie php... fajne to, dobre to jest?
Go to the top of the page
+Quote Post
Speedy
post 7.04.2005, 22:37:54
Post #4





Grupa: Zarejestrowani
Postów: 651
Pomógł: 28
Dołączył: 4.12.2004

Ostrzeżenie: (0%)
-----


  1. <?php
  2. /**
  3.  * Delete a file, or a folder and its contents
  4.  *
  5.  * @author Aidan Lister <aidan@php.net>
  6.  * @version  1.0.2
  7.  * @param  string  $dirname Directory to delete
  8.  * @return bool  Returns TRUE on success, FALSE on failure
  9.  */
  10. function rmdirr($dirname)
  11. {
  12. // Sanity check
  13. if (!file_exists($dirname)) {
  14. return false;
  15. }
  16.  
  17. // Simple delete for a file
  18. if (is_file($dirname)) {
  19. return unlink($dirname);
  20. }
  21.  
  22. // Loop through the folder
  23. $dir = dir($dirname);
  24. while (false !== $entry = $dir->read()) {
  25. // Skip pointers
  26. if ($entry == '.' || $entry == '..') {
  27. continue;
  28. }
  29.  
  30. // Recurse
  31. rmdirr(&#092;"$dirname/$entry\");
  32. }
  33.  
  34. // Clean up
  35. $dir->close();
  36. return rmdir($dirname);
  37. }
  38.  
  39. ?>


--------------------
Sygnatura niezgodna z regulaminem.
Go to the top of the page
+Quote Post
esiek
post 6.11.2008, 15:36:02
Post #5





Grupa: Zarejestrowani
Postów: 65
Pomógł: 0
Dołączył: 6.11.2008
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


<?////////////USUWA WSZYSTKIE PLIKI Z KATALOGU

$katalog = "$delete";

if(glob("$katalog/*")) //sprawdza czy katalog jest pełny. jezeli tak wyswietla ponizsza linię
{
foreach (glob("$katalog/*") as $filename){if($file != '$katalog' && $file != '..'){}unlink("$filename");}}

///////////USUWA KATALOG

rmdir("$delete");

echo"<P ALIGN=CENTER><img SRC=gfx/dobrze.jpg><br>Katalog został pomyślnie usunięty.</P>";
?>


Ja używam czegoś takiego winksmiley.jpg


--------------------
allebhp.pl
Go to the top of the page
+Quote Post
tomek_
post 7.11.2008, 13:18:05
Post #6





Grupa: Zarejestrowani
Postów: 40
Pomógł: 4
Dołączył: 6.11.2008
Skąd: Bytom

Ostrzeżenie: (0%)
-----


ja używam czegoś takiego 

Kod
 function DeleteDir($dir)
    {
     
        $fd = opendir($dir);
        if(!$fd) return false;
        while (($file = readdir($fd))!== false)
        {
            if($file =="." || $file== "..") continue;
            if(is_dir($dir."/".$file))
            {
                  DeleteDir($dir."/".$file);
            }
            else
            {
                unlink("$dir/$file");
            }
        }
        closedir($fd);
        rmdir($dir);
    }


usuwa katalog wraz z wszystkimi jego podkatalogami i plikami w nich zawartymi

Ten post edytował tomek_ 7.11.2008, 13:19:13


--------------------
Dysortografik -> nie besztać za błędy ;P

pomogłem ? -> kliknij "pomógł" ;)
Go to the top of the page
+Quote Post
webdice
post 7.11.2008, 16:14:30
Post #7


Developer


Grupa: Moderatorzy
Postów: 3 045
Pomógł: 290
Dołączył: 20.01.2007




Panowie to nie wykop. Temat zamykam.

~esiek na przyszłość korzystaj z bbcode.
Go to the top of the page
+Quote Post

Closed TopicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 07:56