(PHP 5 >= 5.1.0, PHP 7, PHP 8)
posix_access — Determinar la accesibilidad de un archivo
posix_access() verifica el permiso del usuario sobre un archivo.
filenameEl nombre del archivo a ser probado.
flags
Una máscara consistente de uno o más de los valores POSIX_F_OK ,
POSIX_R_OK , POSIX_W_OK y
POSIX_X_OK .
POSIX_R_OK , POSIX_W_OK y
POSIX_X_OK solicitan que se verifique si el
archivo existe y tiene permisos de lectura, escritura y ejecución,
respectivamente. POSIX_F_OK simplemente
verifica la existencia del archivo.
Ejemplo #1 Ejemplo de posix_access()
Este ejemplo verificará si el $archivo puede leerse y escribirse, de lo contrario imprimirá un mensaje de error.
<?php
$archivo = 'algun_archivo';
if (posix_access($archivo, POSIX_R_OK | POSIX_W_OK)) {
echo '¡El archivo puede leerse y escribirse!';
} else {
$error = posix_get_last_error();
echo "Error $error: " . posix_strerror($error);
}
?>
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.