Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Jak usunąć pliki, foldery powstałe przez skryptphp
domator
post
Post #1





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 25.10.2005

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


No jak w temacie. Nie moge normalnie usunac, aktos mi powiedzial ze jak zdrobilem je przez php to tez je mam tą drogą usunąć, ale jak. Moze znacie kod takiego skryptu co rozwiaze ten problem albo wogole zebym mogl usunac te foldery i pliki
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
Pigula
post
Post #2





Grupa: Zarejestrowani
Postów: 446
Pomógł: 0
Dołączył: 5.03.2005
Skąd: Lublin

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


unlink() i rmdir()
Go to the top of the page
+Quote Post
domator
post
Post #3





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 25.10.2005

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


nic z tego nie czaje. Moze mi ktoś pomóć. Gdzie mam wpisać nazwe dir'a badz files'a??
Go to the top of the page
+Quote Post
Pigula
post
Post #4





Grupa: Zarejestrowani
Postów: 446
Pomógł: 0
Dołączył: 5.03.2005
Skąd: Lublin

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


z manula:
Kod
bool rmdir ( string dirname [, resource context] )

dirname - nazwa katalogu
Kod
bool unlink ( string nazwa_pliku [, resource kontekst] )

jest po polsku!
to juz chyba wiesz gdzie, parametr w nawiasach [ ] jest opcjonalny nie musisz go podawac
Go to the top of the page
+Quote Post
domator
post
Post #5





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 25.10.2005

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


  1. <?php
  2. /**
  3.  * rm() -- Vigorously erase files and directories.
  4.  *
  5.  * @param $fileglob mixed If string, must be a file name (foo.txt), glob pattern (*.txt), or directory name.
  6.  *                        If array, must be an array of file names, glob pattern
    s, or directories.
  7.  */
  8. function rm($fileglob)
  9. {
  10.    if (is_string($fileglob)) {
  11.        if (is_file($fileglob)) {
  12.            return unlink($fileglob);
  13.        } else if (is_dir($fileglob)) {
  14.            $ok = rm("$fileglob/*");
  15.            if (! $ok) {
  16.                return false;
  17.            }
  18.            return rmdir($fileglob);
  19.        } else {
  20.            $matching = glob($fileglob);
  21.            if ($matching === false) {
  22.                trigger_error(sprintf('No files match supplied glob %s', $fileglob), E_USER_WARNING);
  23.                return false;
  24.            }     
  25.            $rcs = array_map('rm', $matching);
  26.            if (in_array(false, $rcs)) {
  27.                return false;
  28.            }
  29.        }     
  30.    } else if (is_array($fileglob)) {
  31.        $rcs = array_map('rm', $fileglob);
  32.        if (in_array(false, $rcs)) {
  33.            return false;
  34.        }
  35.    } else {
  36.        trigger_error('Param #1 must be filename or glob pattern, or array of filenames or glob pattern
    s'
    , E_USER_ERROR);
  37.        return false;
  38.    }
  39.  
  40.    return true;
  41. }
  42. ?>


poprawiam
---
nospor



Gdzie tutaj mam zmienić coś na nazwe pliku?questionmark.gif
Go to the top of the page
+Quote Post
Pigula
post
Post #6





Grupa: Zarejestrowani
Postów: 446
Pomógł: 0
Dołączył: 5.03.2005
Skąd: Lublin

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


$fileglob - przynajmniej z tego co zrozumailem autora o to chodzi

Ten post edytował Pigula 28.10.2005, 17:25:11
Go to the top of the page
+Quote Post
mike
post
Post #7





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

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


To:
  1. <?php
  2. function rm($fileglob)
  3. {
  4.  if (is_string($fileglob)) {
  5.  if (is_file($fileglob)) {
  6.  return unlink($fileglob);
  7.  } else if (is_dir($fileglob)) {
  8.  $ok = rm("$fileglob/*");
  9.  if (! $ok) {
  10.  return false;
  11.  }
  12.  return rmdir($fileglob);
  13.  } else {
  14.  $matching = glob($fileglob);
  15.  if ($matching === false) {
  16.  trigger_error(sprintf('No files match supplied glob %s', $fileglob), E_USER_WARNING);
  17.  return false;
  18.  }  
  19.  $rcs = array_map('rm', $matching);
  20.  if (in_array(false, $rcs)) {
  21.  return false;
  22.  }
  23.  }  
  24.  } else if (is_array($fileglob)) {
  25.  $rcs = array_map('rm', $fileglob);
  26.  if (in_array(false, $rcs)) {
  27.  return false;
  28.  }
  29.  } else {
  30.  trigger_error('Param #1 must be filename or glob pattern, or array of filenames or glob pattern
    s'
    , E_USER_ERROR);
  31.  return false;
  32.  }
  33.  
  34.  return true;
  35. }
  36. ?>

jest funkcja, a żeby funkcja zadziałała, trzeba ją wywołać:
  1. <?php
  2.  
  3. $strFileToDelete = 'some_file.txt';
  4.  
  5. rm( $strFileToDelete );
  6.  
  7. ?>
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 01:49