CakeFest 2024: The Official CakePHP Conference

posix_access

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

posix_accessBir dosyanın izinlerine bakar

Açıklama

posix_access(string $dosya, int $seçenekler = 0): bool

Belirtilen dosya için kullanıcının izinlerine bakar.

Bağımsız Değişkenler

dosya

Sınanacak dosyanın yolu.

seçenekler

Şunların biri veya birkaçından oluşan bir bit maskesi: POSIX_F_OK, POSIX_R_OK, POSIX_W_OK ve POSIX_X_OK.

POSIX_R_OK, POSIX_W_OK ve POSIX_X_OK sabitleri ile sırayla dosyanın mevcudiyeti ve okunabilirliği, yazılabilirliği ve çalıştırılabilirliği sınanır. Dosyanın sadece mevcudiyetine bakmak için POSIX_F_OKkullanılabilir.

Dönen Değerler

Başarı durumunda true, başarısızlık durumunda false döner.

Örnekler

Örnek 1 - posix_access() örneği

Bu örnekte, bir dosyanın okunabilir ve yazılabilir olup olmadığına bakılmakta, değilse bir hata iletisi gösterilmektedir.

<?php

$file
= 'bir_dosya';

if (
posix_access($file, POSIX_R_OK | POSIX_W_OK)) {
echo
'Dosya hem okunabiliyor hem de yazılabiliyor!';

} else {
$error = posix_get_last_error();

echo
"Hata $error: " . posix_strerror($error);
}

?>

Notlar

Ayrıca Bakınız

add a note

User Contributed Notes 1 note

up
-1
unixguy at earth dot com
9 years ago
It should be noted that this function performs access checks based on the real UID and real GID of the process running PHP. These aren't necessarily the same as the effective UID and GID.

In other words, it may well be that access() returns “true” for a particular permission, but an fopen() operation which requires the same permission will fail, and vice versa.

Keep that in mind if you use access() for such checks.
To Top