array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'es', ), 'this' => array ( 0 => 'function.chown.php', 1 => 'chown', ), 'up' => array ( 0 => 'ref.filesystem.php', 1 => 'Funciones del Sistema de Archivos', ), 'prev' => array ( 0 => 'function.chmod.php', 1 => 'chmod', ), 'next' => array ( 0 => 'function.clearstatcache.php', 1 => 'clearstatcache', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'es', 'path' => 'reference/filesystem/functions/chown.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
chown — Cambia el propietario del fichero
Intenta cambiar el propietario del fichero filename
por el usuario user
. Sólo el superusuario puede cambiar el
propietario de un fichero.
filename
La ruta hacia el fichero.
user
Un nombre o número de usuario.
Ejemplo #1 Uso sencillo de chown()
<?php
// El nombre de fichero y el nombre de usuario a emplear
$nombre_fichero= "foo.php";
$ruta = "/home/sites/php.net/public_html/sandbox/" . $nombre_fichero ;
$nombre_usuario = "root";
// Establecer el usuario
chown($ruta, $nombre_usuario);
// Verificar el resultado
$stat = stat($ruta);
print_r(posix_getpwuid($stat['uid']));
?>
El resultado del ejemplo sería algo similar a:
Array ( [name] => root [passwd] => x [uid] => 0 [gid] => 0 [gecos] => root [dir] => /root [shell] => /bin/bash )
Nota: Esta función no funcionará en ficheros remotos ya que el fichero debe ser accesible vía el sistema de ficheros del servidor para poder ser examinado.