Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] wybór folderu i usunięcie z niego pliku, problem z usunięciem plików z podkatalogu
felixk
post
Post #1





Grupa: Zarejestrowani
Postów: 90
Pomógł: 1
Dołączył: 31.01.2009
Skąd: Ostrołęka

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


Witam, tworzę mały system archiwum, który umożliwiał będzie podgląd listy folderów i następnie wybór jednego z nich i wyświetlenie jego zawartości w postaci tabeli. Każdy element osobno może być usunięty. O ile teoretycznie wybór działa to usuwanie już nie bardzo. Zmienna dir po kliknięciu w submit zawiera ścieżkę w formie "archiwum/folder", mimo wszystko pliki z podfolderu i tak się nie usuwają. Poniżej kod. Z góry dziękuję za wszelką pomoc

  1. <?php
  2. $rok = gmdate("Y");
  3. ?>


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.  
  4.  
  5. <script type="text/javascript">
  6. function confirmDelete2(delUrl) {
  7. if (confirm("Czy na pewno chcesz usunąć plik z serwera? Usunięcie jest nieodwracalne")) {
  8. document.location = delUrl;
  9. }
  10. }
  11.  
  12. </head>

  1. <?php
  2.  
  3. $akcja = isset($_GET['akcja']) ? $_GET['akcja'] : ' ';
  4.  
  5. if($akcja == "pokaz_archiwum")
  6. {
  7.  
  8. echo '<form name="form" action="" method="post">';
  9. echo '<ul style="list-style: none">';
  10. foreach(glob('archiwum/*', GLOB_ONLYDIR) as $directory) {
  11. $dir = str_replace('archiwum/', '', $directory);
  12. echo '<li><input type="radio" name="folder" value="'.$dir.'" />'.$dir.'</li>';
  13. echo '</ul>';
  14. echo '<input type="submit" value="Wybierz folder" name="btn" />';
  15. echo '</form>';
  16. }
  17.  
  18. $folder = $_POST['folder']
  19.  
  20. $dir = "archiwum".'/'."$folder";
  21.  
  22. if ( $handle = opendir ( $dir ) )
  23. {
  24. while ( false !== ( $file = readdir ( $handle ) ) )
  25. {
  26. if ( ( $file != '.' ) && ( $file != '..' ) )
  27. {
  28. $files[] = $file;
  29. }
  30. }
  31. closedir ( $handle );
  32. }
  33.  
  34. if ( !empty ( $files ) )
  35. {
  36. sort ( $files );
  37.  
  38. <fieldset>
  39. <legend>Pliki w aktualnie wybranym katalogu</legend>
  40. <table align="center" border="1" width="100" cellpadding="0" cellspacing="0">
  41. <tr>
  42. <td>Nazwa pliku na serwerze</td>
  43. <td>Plik</td>
  44. <td>Usuń plik</td>
  45. </tr>';
  46.  
  47. for($i = 0, $c = count($files); $i < $c; $i++) {
  48.  
  49. $names[] = pathinfo($files[$i], PATHINFO_FILENAME);
  50.  
  51. echo '<tr>
  52. <td>'.$files[$i].'</td>
  53. <td>'.$names[$i].'</td>';
  54.  
  55.  
  56. if (isset($_GET['usun'])){
  57. $usun = $_GET['usun'];
  58.  
  59. if(file_exists($dir.'/'.$usun) & $usun!=""){
  60. unlink($dir.'/'.$usun);
  61. }
  62. }
  63.  
  64. if (($files[$i] != '.') & ($files[$i] != '..') & ($files[$i]!= "")& !is_dir($files[$i])) {
  65. echo "<td><a title=\"Klknij, aby usunąć plik z serwera\" href=\"java script:confirmDelete2('index.php?akcja=pokaz_archiwum&amp;usun=$files[$i]')\">$names[$i]</a></td>";
  66.  
  67. }
  68. echo'</tr>';
  69. }
  70.  
  71. if ($usun)
  72. {
  73. echo 'Plik usunięty!';
  74. }
  75.  
  76. echo '</table></fieldset>';
  77. }
  78. ?>

  1. </body>
  2. </html>


Ten post edytował felixk 25.08.2013, 07:50:05
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 7.10.2025 - 02:53