PHP 5.4.36 Released

is_readable

(PHP 4, PHP 5)

is_readableTells whether a file exists and is readable

Descrierea

bool is_readable ( string $filename )

Tells whether a file exists and is readable.

Parametri

filename

Path to the file.

Valorile întoarse

Returns TRUE if the file or directory specified by filename exists and is readable, FALSE otherwise.

Exemple

Example #1 is_readable() example

<?php
$filename 
'test.txt';
if (
is_readable($filename)) {
    echo 
'The file is readable';
} else {
    echo 
'The file is not readable';
}
?>

Erori/Excepții

În cazul eșecului este emis un E_WARNING.

Note

Keep in mind that PHP may be accessing the file as the user id that the web server runs as (often 'nobody'). Safe mode limitations are not taken into account before PHP 5.1.5.

Notă: Rezultatele acestei funcții sunt stocate în cache. Accesați clearstatcache() pentru mai multe detalii.

Sfat

Începând cu PHP 5.0.0 această funcție poate fi utilizată de asemenea cu unele învelișuri URL. Referiți-vă la Supported Protocols and Wrappers pentru a determina care învelișuri susțin familia de funcționalitate stat().

Notă:

The check is done using the real UID/GID instead of the effective one.

This function may return TRUE for directories. Use is_dir() to distinguish file and directory.

Vedeți de asemenea

add a note add a note

User Contributed Notes 3 notes

up
3
jo at durchholz dot org
8 years ago
DrTebi at yahoo dot com is wrong. is_readable() checks whether you can do file_get_contents() or similar calls, no more, no less. If the location given returns a 500 or 403 error, you can still read() that (you'll simply get the error page), but it's still read()able. Using is_readable to check the validity of a URL is simply the wrong function.
up
0
pgl at yoyo dot org
5 years ago
Note that is_readable() will return false for streams, eg, php://stdin.
up
-1
Anonymous
9 years ago
Sometimes in situations where file_exists fails (returns false even though the file does exist) stat will work.
To Top