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: 19
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]

is_file

(PHP 3, PHP 4, PHP 5)

is_file -- Mówi czy nazwa_pliku jest zwykłym plikiem

Opis

bool is_file ( string nazwa_pliku )

Zwraca TRUE jesli nazwa_pliku istnieje i jest zwykłym plikiem.

Notatka: Wyniki działania tej funkcji są buforowane. Zobacz opis funkcji clearstatcache() aby uzyskać więcej informacji.

Podpowiedź: Od wersji 5.0.0 PHP ta funkcja może być użyta także z niektórymi wrapperami URL. Zobacz Dodatek L aby uzyskać listę wrapperów które obsługują funkcjonalność z rodziny stat().

Patrz także: is_dir() i is_link().




User Contributed Notes

Emin Sadykhov (azdg_nospam at azdg dot com)
12-Dec-2005 02:57

File operations such as is_file (also is_dir, opendir, readdir) work slower with Absolute paths - processing time is increase in 2-3 times.

Current rule is actual only for PHP5 (tested on 5.0.4, 5.1.1, Windows and Linux, 1st and 2nd Apache)

Try to use relative paths in these operators.

Example tested on my machine:
<?php
# note: in the both conditions file really exists!

# WIN XP, PHP4
# processing time: ~ 0.0003 sec.
if(is_file("images/10.jpg")) echo 'file exists';

# processing time: ~ 0.0002 sec. !!!
if(is_file("C:/server/htdocs/mysite/images/10.jpg")) echo 'file exists';

# WIN XP, PHP5
# processing time: ~ 0.0004 sec.
if(is_file("images/10.jpg")) echo 'file exists';

# processing time: ~ 0.0010 sec.
if(is_file("C:/server/htdocs/mysite/images/10.jpg")) echo 'file exists';
?>


Jonathan Shaltz
14-Oct-2005 07:23

Maybe this is a newbie mistake, but note that paths are relative to the filesystem and the location of the script.  This means that MS IIS virtual directories are not available by relative path - use an absolute.
This threw me because virtual directories ARE available for URLs, at least on IIS.


bill fumerola
31-Aug-2005 03:45

be careful, is_file() fails on files larger than your integer storage (2^32 for most).

Warning: is_file(): Stat failed for bigfile (errno=75 - Value too large for defined data type)


mariodivece at bytedive dot com
23-Aug-2005 12:06

Hi... just a neat way of showing up file icons that correspond to their mimetypes

Here's the code:
<?php
function mimetypeicon($mimetype) {
  
$newmime = str_replace('/','-',$mimetype);
  
   if(
is_file('images/16x16/gnome-mime-'.$newmime.'.png')) {
       return
'images/16x16/gnome-mime-'.$newmime.'.png';
   }
   else {
      
//The mimetype icon was not found
      
return 'images/16x16/gnome-mime-text.png';
   }
}
?>


punknroll at gmx dot at
11-Aug-2005 05:11

is_file returns false if you don't have the permissions for the file or the directory (eg.: you are web34 and the directory belongs to root)!


kkrizka at gmail dot com
04-Jun-2005 07:03

The following will "guess" if something is a file in case it is not availible.

function isfile($page) {
  //get the top file/dir
  $file=basename($page);

  // ends in a slash, so is a dir
  if(substr($file,strlen($file)-1)=='/') {
   return false;
  }

  //find all dots
  $a=explode('.',$file);
  //there is a dot, means it is a file with a extension
  //beware of http://www.site.com
  if(count($a)>1) {
   return true;
  } else {
   return false
  }
}


08-Mar-2005 06:02

### Symbolic links are resolved ###

If you pass a symlink (unix symbolic link) as parameter, is_file will resolve the symlink and will give information about the refered file. For example:

  touch file
  ln -s file link
  echo '<? if (is_file("link")) echo "y\n"; ?>' | php -q

will print "y".

is_dir resolves symlinks too.


ludvig dot ericson at gmail dot com
25-Oct-2004 08:06

I tend to use alot of includes, and I found that the is_file is based on the script executed, not ran.
if you request /foo.php and foo.php looks like this:
<?php
include('foobar/bar.php');
?>
and bar.php looks like this:
<?php
echo (is_file('foo/bar.txt'));
?>

Then PHP (on win32, php 5.x) would look for /foo/bar.txt and not /foobar/foo/bar.txt.
you would have to rewrite the is_file statement for that, or change working directory.
Noting this since I sat with the problem for some time,

cheers, Toxik.


rehfeld.us
04-Sep-2004 12:04

regarding rlh at d8acom dot com method,

It is incorrect. Well, it works but you are not guaranteed the file extension using that method.

for example :  filename.inc.php

your method will tell you the ext is "inc", but it is in fact "php"

heres a way that will work properly.

<?php

$dh
= opendir($dir);

while (
false !== ($document = readdir($dh))) {
  
$pos = strrpos($document, '.');
   if (
false !== $pos && strlen($document) > $pos + 1) {
      
$ext = substr($document, $pos + 1);
   }
}

?>


rlh at d8acom dot com
12-Feb-2003 02:17

I do a lot of file parsing and have found the following technique extremely useful:

while (false !== ($document = readdir($my_dir)))
{
   $ext=explode('.',$document);
   if($document != '.' && $document != '..' && $ext[1])
   {
                       'Do something to file...'
             }
}

It gets around the fact that, when working on website pages, the html files are read as directories when downloaded. It also allows you to extend the usefulness of the above method by adding the ability to determine file types e.g.

if($document != '.' && $document != '..' && $ext[1]=='htm')
or
if($document != '.' && $document != '..' && $ext[1]=='doc')


andreas dot stagl at fits dot at
27-Mar-2002 08:34

if you're running apache as a service on a win32 machine, an you try to determinate if a file on an other pc in your network exists - ex.: is_file('//servername/share/dir1/dir2/file.txt') - you may return false when you're running the service as LocalSystem. To avoid this, you have to start the Apache-Service as a 'registered' domain user.


quietust at ircN dot org
14-Dec-2001 05:20

In PHP 4.1.0 under win32, this seems to print out a warning message if the file does not exist (using error_reporting = E_ALL & ~E_NOTICE).


amraam at ao dot net
12-Mar-2000 03:56

It seems that is_file doesn't return true for a file that is 0 bytes.  Perhaps it is something with the file system.  I am using IIS 3.0 on an NT4 box.  I worked around it using !is_dir($filename) but that seems a clunky way to do it.


 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt