PHP 8.4.0 RC3 available for testing

chown

(PHP 4, PHP 5, PHP 7, PHP 8)

chownCambia il proprietario del file

Descrizione

chown(string $filename, mixed $user): bool

Tenta di cambiare il proprietario del file filename nell'utente user. Solo il superuser può cambiare il proprietario di un file.

Elenco dei parametri

filename

Percorso del file.

user

Un nome utente o un numero.

Valori restituiti

Restituisce true in caso di successo, false in caso di fallimento.

Esempi

Example #1 Semplice utilizzo di chown()

<?php

// Nome file e nome utente da utilizzare
$file_name= "foo.php";
$path = "/home/sites/php.net/public_html/sandbox/" . $file_name ;
$user_name = "root";

// Imposta l'utente
chown($path, $user_name);

// Controlla il risultato
$stat = stat($path);
print_r(posix_getpwuid($stat['uid']));

?>

Il precedente esempio visualizzerà qualcosa simile a:

Array
(
    [name] => root
    [passwd] => x
    [uid] => 0
    [gid] => 0
    [gecos] => root
    [dir] => /root
    [shell] => /bin/bash
)

Note

Nota: Questa funzione non opererà su file remoti perché il file che deve essere esaminato deve essere accessibile attraverso il filesysmte del server.

Nota: Su Windows, questa funzione fallisce silenziosamente se applicata su un file normale.

Vedere anche:

  • chmod() - Cambia le impostazioni del file
  • chgrp() - Cambia il gruppo del file

add a note

User Contributed Notes 1 note

up
7
martijn at sigterm dot nl
21 years ago
If chown is filled with a variable ( chown ("myfile", $uid) the uid will be looked up through pwget_uid.

So if you need to set a non existing uid use inval($uid).
To Top