★ wanayoo — archive 1999 http://fr.php.net/manual/fr/function.chmod.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links 
search for in the  
<chgrpchown>
Last updated: Wed, 15 Jan 2003
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese (Simplified) | Chinese (Hong Kong Cantonese) | Chinese (Traditional) | Czech | Dutch | Finnish | German | Hebrew | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Slovak | Slovenian | Spanish | Swedish | Turkish

chmod

(PHP 3, PHP 4 )

chmod -- Change le mode du fichier.

Description

int chmod ( string filename, int mode)

chmod() remplace le mode du fichier filename par le mode mode.

Il est à noter que le mode mode est considéré comme un nombre en notation octale. Afin de vous en assurer, vous pouvez préfixer cette valeur par un zéro (mode):

<?php
  chmod( "/somedir/somefile", 755 );
// notation décimale; probablement FALSE
  chmod( "/somedir/somefile", 0755 );
// notation octale; valeur du mode correcte
?>

chmod() renvoie TRUE en cas de succès, FALSE sinon.

Voir aussi chown() et chgrp().

Note : chmod() ne fonctionne pas sous Windows.

User Contributed Notes
chmod
add a note about notes
gnettles2 at home dot com
24-Aug-2001 06:20

Usually when you're trying to write to af file, you'll need to chmod the file to something like 666 or 755. You can use a command to chmod the file for you, which is especially useful when you're making a script where you're setting it up so that your users don't have to peform a bunch of actions to setup the script. When i wrote my news program script, I only had two files. install.php and config.php. All you had to do was chmod install.php to 666 and open it up in a web browser and answer a few questions. The script itself setup the rest of the files and chmodded them for you.
jon at zend dot com
15-Oct-2001 03:37

if 'mode' is held in a variable and is and octal value you need to convert it to decimal before passing it to the function:
chmod ($filename, octdec($mode))

FF7Cayn at gmx dot de
28-Oct-2001 12:09

It does work on Windows.
I use Win 98 with the Sambar Server.
The only chmods allowed are the 775 and 666 mod. 775 for non-writeable and 666 for writeable. The only thing is that the usergroups doesn't work.
Note: the 0 at the start doesn't work with windows. use only the decimal kind.
Have fun :)

mail at philipp-louis dot de
24-Mar-2002 08:08

For those not so familiar with UNIX file modes, this might be helpful:

http://bruce-hamilton.com/tutorials/chmod.shtml

Again, never forget that the file mode must be passed as an *octal* value, not as a decimal number or a string. So it must be 0755 instead of 755 or "755", for example. This is a very common pitfall.

advvft at ifrance dot com
24-Oct-2002 10:18

This function is very often disabled by the hosting services company.
So it is quite impossible to make an upload when you can't change the rights on a file.

Half-Dead at nospam dot com
08-Nov-2002 09:42

[Editor's note:
That is due the fact Win32 systems treat premissions. You do not really have any other levels but read-only.

Maxim]


On WinME with apache chmod also works to a certain limit.

What happens is that apparently only the first number is counted, so 0666 (read-write) is the same as 0777, 0644, 0600, etc, and 0444 (read-only) is the same as 477, 400, etc.

..didn't test 0500 series

benesNO_SPAM at 3dsrc dot com
14-Dec-2002 10:27

Be careful with in the function chmod ( string filename, int mode), "filename" must be contain the full path of the file.

Ex :
chmod ("../file", 0755) won't work.

chmod ("/somedir/somefile", 0755) will work.

add a note about notes

<chgrpchown>
Last updated: Wed, 15 Jan 2003
show source | credits | stats | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Thu Jan 30 04:17:33 2003 CET