Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 65
W CZYM MOGĘ POMÓC?


   
OPINIE UŻYTKOWNIKÓW
Gratulacje i dzięki! Trafiłem tu przypadkiem poszukując informacji na temat php+mysql. Wiele polskich stron powiela identyczne przykłady, klonuje te same kursy i lekcje... ten serwis okazał sie inny. Zasada "problem - rozwiazanie - wyjaśnienie" zdaje egzamin - zapewnia jasną, jednoznaczną i pewną pomoc w konkretnym przypadku. Porady są warte swojej ceny, przede wszystkim ze względu na przyjazną (także dla początkujących) formę i treść oraz bogate i stale powiększane zasoby. Polecam i pozdrawiam!

Kamil Dmowski
Polski Czerwony Krzyż

   
GALERIA FOTOGRAFII
   
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net

[Spis] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [X] [W] [Z]

unlink

(PHP 3, PHP 4, PHP 5)

unlink -- Kasowanie pliku

Opis

bool unlink ( string nazwa_pliku [, resource kontekst] )

Kasuje nazwa_pliku. Podobnie do funkcji unlink() z Unix'owego C. Zwraca TRUE w przypadku sukcesu, FALSE w przypadku porażki.

Notatka: W PHP 5.0.0 unlink() może być użyta z niektórymi wrapperami URL. Skorzystaj z Dodatek L aby uzyskać listę wrapperów, które obsługują unlink().

Notatka: Wsparcie dla kontekstów zostało dodane w PHP 5.0.0.

Patrz także: rmdir() do kasowania katalogów.




User Contributed Notes

stefano at takys dot it
28-Dec-2005 12:57

A short but powerfull recursive function that works also if the dirs contain hidden files

function SureRemoveDir($dir) {
   if(!$dh = @opendir($dir)) return;
   while (($obj = readdir($dh))) {
     if($obj=='.' || $obj=='..') continue;
     if (!@unlink($dir.'/'.$obj)) {
         SureRemoveDir($dir.'/'.$obj);
     } else {
         $file_deleted++;
     }
   }
   if (@rmdir($dir)) $dir_deleted++;
}


Anarcho at ssm-clan dot de
26-Nov-2005 11:56

Just to be a bit more accurate to the post of "jchase at solidmark dot com":

On unixoide systems you only need write permission for the directory to delete a file. The permissions of the file are nonrelevant.

You need file permissions if you want to change the file data or to read the data.


bishop
05-Jun-2005 09:30

<?php
/**
 * rm() -- Vigorously erase files and directories.
 *
 * @param $fileglob mixed If string, must be a file name (foo.txt), glob pattern (*.txt), or directory name.
 *                        If array, must be an array of file names, glob patterns, or directories.
 */
function rm($fileglob)
{
   if (
is_string($fileglob)) {
       if (
is_file($fileglob)) {
           return
unlink($fileglob);
       } else if (
is_dir($fileglob)) {
          
$ok = rm("$fileglob/*");
           if (!
$ok) {
               return
false;
           }
           return
rmdir($fileglob);
       } else {
          
$matching = glob($fileglob);
           if (
$matching === false) {
              
trigger_error(sprintf('No files match supplied glob %s', $fileglob), E_USER_WARNING);
               return
false;
           }     
          
$rcs = array_map('rm', $matching);
           if (
in_array(false, $rcs)) {
               return
false;
           }
       }     
   } else if (
is_array($fileglob)) {
      
$rcs = array_map('rm', $fileglob);
       if (
in_array(false, $rcs)) {
           return
false;
       }
   } else {
      
trigger_error('Param #1 must be filename or glob pattern, or array of filenames or glob patterns', E_USER_ERROR);
       return
false;
   }

   return
true;
}
?>


jchase at solidmark dot com
21-May-2005 07:05

[Editor's note: A suggestion for a work-around was submitted by argistof at gmail dot com: You can use the recursive option (see man chmod) when chmodding, for instance 'chmod 777 directory/ -R'. Be aware though, this will change the permissions of all files and folders in the diectory.]

Just a note which you probably all know, but I didn't, and it might save another poor sap some unnecessary time:

I was doing unlink() and fopen() on a file and got a permission denied error, even after chmoding the file to 0777. 

The folder that contains the file must ALSO have write permission.  Took a headache to find this out. 

Hope this helps someone :)


kickthedonkey at gmail dot com
17-May-2005 01:24

Regarding the comment by 'admin at crazydrumguy dot info':  You might want to consider using is_file instead of file_exists if you're wanting to target a file specifically (and not a directory).  file_exists($name) will return true if $name contains a path to a directory (which may or may not be what you want to do...)


ashley at semantic dot org
02-Apr-2005 12:50

Actually you should use "@unlink" rather than testing with file_exists. The former is atomic, whereas the latter can break if you can't guarantee only one process will try to delete a given file at a time.


dagski_AT_gmail_DOT_com
07-Feb-2005 07:19

before you could unlink a file created which uses a handle e.g.,

$handle = sqlite('temp.db');

unset($handle); first befofe
unlink($handle);

to avoide permission denied error.


admin at crazydrumguy dot info
23-Jan-2005 02:43

Regarding the previous note, you can accomplish the same thing by using file_exists.
<?php
if(file_exists($file))
unlink($file);
?>


xenon54 at generationphp dot net
29-Dec-2004 05:03

Use @ to avoid having a warning error if the file is not found.

<?php
$return
= @unlink('filename.txt');
// Return FALSE if not found
var_dump($return);
?>


chris at vibenewmedia dot com
14-Sep-2004 07:54

To delete all files of a particular extension, or infact, delete all with wildcard, a much simplar way is to use the glob function.  Say I wanted to delete all jpgs .........

<?php

foreach (glob("*.jpg") as $filename) {
   echo
"$filename size " . filesize($filename) . "\n";
  
unlink($filename);
}

?>


pc AT newagelab DOT com DOT ua
08-Sep-2004 05:22

To delete files using wildcards:

<?
function delfile($str)
{
   foreach(
glob($str) as $fn) {
      
unlink($fn);
   }
}
?>


 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt