使用mkdir创建文件夹时,发现这个函数有两个参数,第二个参数是为新创建的文件夹指定权限。
但是如果直接用mkdir('文件地址', 0777);时 发现新文件夹的权限并不是777,一般情况下会是022。
因为mkdir在给文件夹制定权限时,会跟当前登录操作系统用户的umask(用户缺省权限属 性)值进行位“与”,得到的值才是最终权限值。
umask 是什么?
我们创建文件的默认权限是怎么来的?如何改变这个默认权限呢?
当我们登录系统之后创建一个文件总是有一个默认权限的,那么这个权限是怎么来的呢?这就是 umask 干的事情。
umask 设置了用户创建文件的默认权限,它与 chmod 的效果刚好相反,umask 设置的是权限“补码”,而 chmod 设置的是文件权限码。一般在 /etc/profile、$HOME/.bash_profile 或 $HOME/.profile 中设置 umask 值。
如何计算 umask 值?
umask 命令允许你设定文件创建时的缺省模式,对应每一类用户(文件属主、同组用户、其他用户)存在一个相应的 umask 值中的数字。对于文件来说,这一数字的最大值分别是 6。系统不允许你在创建一个文本文件时就赋予它执行权限,必须在创建后用 chmod 命令增加这一权限。目录则允许设置执行权限,这样针对目录来说,umask 中各个数字最大可以到 7。
该命令的一般形式为:umask nnn,其中 nnn 可为 000 - 777。
我们只要记住 umask 是从权限中“拿走”相应的位即可。
如:umask 值为 022,则默认目录权限为 755,默认文件权限为 644。
所以,如果用户umask是022(一般默认是这个),即:000 010 010 在于mkdir指定的777 ,即:111 111 111 位“与”后,得到的真实权限为:022。
如果想让新建文件夹权限最大,有两种方法可以实现:(当然,是在当前用户能赋予最高权限的条件下)
1、修改用户umask,php提供有umask函数:
复制代码 代码如下:
$oldumask=umask(0);
mkdir('test',0777);
umask($oldumask);
这种方法看起来一劳永逸,在脚本开头文件里指定下umask值,后面直接用mkdir就可以控制权限,需要注意的是:在多线程服务器上使用umask函数时,多个线程会公用一个umask,所以可能会造成混乱。
2、使用chmod函数,这也是最常用的方法:
复制代码 代码如下:
mkdir('文件地址', 0777);
chmod('文件地址', 0777);
最后,需要注意一点,权限值最好使用八进制表示,即“0”开头,而且一定不要加引号。

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!