Hướng dẫn php mkdir cannot create directory - php mkdir không thể tạo thư mục

5

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Khi tôi tạo thư mục mới với mkdir($path, 0755);, tôi có lỗi:

Cảnh báo: mkdir () [function.mkdir]: quyền từ chối trong /home/u23555603/public_html/vacancies/index.php trên dòng 51

Trong thư mục "Vị trí tuyển dụng" tôi có 755 quyền.

Tôi nên làm gì?

Cảm ơn vì sự giúp đỡ.

Đã hỏi ngày 2 tháng 3 năm 2015 lúc 9:20Mar 2, 2015 at 9:20

9

Như những người khác đã nói, hãy đảm bảo thư mục của bạn có thể ghi được bởi người dùng máy chủ của bạn chạy theo. Đối với Apache dưới *Nix, bạn có thể làm:

ps aux | egrep 'apache|http|nginx'

Và tìm kiếm (các) tên người dùng trong cột đầu tiên.

Đối với việc tạo một thư mục trong PHP một cách an toàn, hãy kiểm tra kết quả của is_writable($parentDir) trước khi thử tạo thư mục. Xem IS_WRITY.

Đã trả lời ngày 3 tháng 5 năm 2015 lúc 7:40May 3, 2015 at 7:40

Tại sao MKDIR không tạo thư mục?

<?php mkdir('newdir', 0777); ?>

MKDIR: Không thể tạo thư mục - quyền từ chối lý do cho lỗi này là người dùng bạn đang chạy MKDIR là, không có quyền tạo thư mục mới ở vị trí bạn đã chỉ định. Bạn nên sử dụng lệnh LS trên thư mục cấp cao hơn để xác nhận quyền.

<?php mkdir('/var/www/PhpProject3/newdir',0777); ?>

Làm cách nào để sửa chữa quyền MKDIR bị từ chối?

<?php echo 'Great'; ?>

[ErrorException] mkdir (): sự cho phép bị từ chối. Điều đó có nghĩa là bạn không có quyền viết trên thư mục dự án của mình. Tạo một thư mục mới, giả sử 'myProject và chạy sudo chmod 777 myProject. Sau đó chuyển sang thư mục' myProject 'và tạo dự án.

Làm thế nào tạo thư mục nếu không tồn tại trong PHP?

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>

Phương pháp: File_Exists (): Đây là một hàm sẵn được sử dụng để kiểm tra xem một tệp hoặc thư mục có tồn tại hay không. is_dir (): Nó cũng được sử dụng để kiểm tra xem một tệp hoặc thư mục có tồn tại hay không. MKDIR (): Hàm này tạo ra một thư mục.

Ai giúp tôi với ?

(Php 4, Php 5, Php 7, Php 8)

MKDIR - Làm thư mụcMakes directory

Sự mô tả

MKDIR (& nbsp; & nbsp; & nbsp; & nbsp; chuỗi ____ ____ 8, & nbsp; & nbsp; & nbsp; & nbsp; int $permissions = 0777, & nbsp; = <?php mkdir('newdir', 0777); ?> 3): Bool(
    string $directory,
    int $permissions = 0777,
    bool <?php mkdir('newdir', 0777); ?> 0 = <?php mkdir('newdir', 0777); ?> 1,
    ?resource <?php mkdir('newdir', 0777); ?> 2 = <?php mkdir('newdir', 0777); ?> 3
): bool

Thông số

<?php mkdir('newdir', 0777); ?> 4

Đường dẫn thư mục.

Mẹo

Một URL có thể được sử dụng như một tên tệp với chức năng này nếu các giấy gói fopen đã được bật. Xem fopen () để biết thêm chi tiết về cách chỉ định tên tệp. Xem các giao thức và trình bao bọc được hỗ trợ để biết các liên kết đến thông tin về những khả năng mà các trình bao bọc khác nhau có, ghi chú về việc sử dụng của chúng và thông tin về bất kỳ biến được xác định trước mà họ có thể cung cấp.fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.

<?php mkdir('newdir', 0777); ?> 5

Các quyền là 0777 theo mặc định, có nghĩa là quyền truy cập rộng nhất có thể. Để biết thêm thông tin về quyền, hãy đọc chi tiết trên trang chmod ().chmod() page.

Ghi chú::

<?php mkdir('newdir', 0777); ?> 5 bị bỏ qua trên Windows.

Lưu ý rằng bạn có thể muốn chỉ định <?php mkdir('newdir', 0777); ?> 5 là một số bát phân, điều đó có nghĩa là nó sẽ có số 0 hàng đầu. <?php mkdir('newdir', 0777); ?> 5 cũng được sửa đổi bởi UMASK hiện tại, bạn có thể thay đổi bằng Umask ().umask().

<?php mkdir('newdir', 0777); ?> 9

Nếu <?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 0, thì bất kỳ thư mục mẹ nào cho <?php mkdir('newdir', 0777); ?> 4 được chỉ định cũng sẽ được tạo, với cùng các quyền.<?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 0, then any parent directories to the <?php mkdir('newdir', 0777); ?> 4 specified will also be created, with the same permissions.

<?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 2

Một tài nguyên luồng ngữ cảnh.resource.

Trả về giá trị

Trả về <?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 0 khi thành công hoặc <?php mkdir('newdir', 0777); ?> 1 về thất bại.<?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 0 on success or <?php mkdir('newdir', 0777); ?> 1 on failure.

Ghi chú::

<?php mkdir('newdir', 0777); ?> 5 bị bỏ qua trên Windows.<?php mkdir('newdir', 0777); ?> 1 will still be returned. Use is_dir() or file_exists() to check if the directory already exists before trying to create it.

Errors/Exceptions

Lưu ý rằng bạn có thể muốn chỉ định <?php mkdir('newdir', 0777); ?> 5 là một số bát phân, điều đó có nghĩa là nó sẽ có số 0 hàng đầu. <?php mkdir('newdir', 0777); ?> 5 cũng được sửa đổi bởi UMASK hiện tại, bạn có thể thay đổi bằng Umask ().<?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 6 level error if the directory already exists.

<?php mkdir('newdir', 0777); ?> 9<?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 6 level error if the relevant permissions prevent creating the directory.

Nếu <?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 0, thì bất kỳ thư mục mẹ nào cho <?php mkdir('newdir', 0777); ?> 4 được chỉ định cũng sẽ được tạo, với cùng các quyền.

<?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 2mkdir() example

<?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 8

Một tài nguyên luồng ngữ cảnh.mkdir() using the <?php mkdir('newdir', 0777); ?> 9 parameter

<?php echo 'Great'; ?> 0

Trả về giá trị

  • Trả về <?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 0 khi thành công hoặc <?php mkdir('newdir', 0777); ?> 1 về thất bại.
  • Nếu thư mục được tạo đã tồn tại, đó được coi là lỗi và <?php mkdir('newdir', 0777); ?> 1 vẫn sẽ được trả về. Sử dụng is_dir () hoặc file_exists () để kiểm tra xem thư mục đã tồn tại trước khi cố gắng tạo nó.
  • Phát ra lỗi cấp <?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 6 nếu thư mục đã tồn tại.

Phát ra lỗi cấp <?php mkdir('/var/www/PhpProject3/newdir',0777); ?> 6 nếu các quyền có liên quan ngăn chặn việc tạo thư mục.

Ví dụ

<?php echo 'Great'; ?> 1

<?php echo 'Great'; ?> 2

<?php echo 'Great'; ?> 3

<?php echo 'Great'; ?> 4

<?php echo 'Great'; ?> 5

Ví dụ #1 MKDIR () Ví dụ

Ví dụ #2 mkdir () sử dụng tham số <?php mkdir('newdir', 0777); ?> 9

<?php echo 'Great'; ?> 6

<?php echo 'Great'; ?> 7

<?php echo 'Great'; ?> 8

<?php echo 'Great'; ?> 5

Xem thêm

is_dir () - cho biết tên tệp có phải là thư mục

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost> 0

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost> 1

<?php echo 'Great'; ?> 5

rmdir () - Xóa thư mục

Umask () - Thay đổi UMASK hiện tại

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost> 3

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost> 4

<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost> 5

<?php echo 'Great'; ?> 5

Tại sao MKDIR không tạo thư mục?

MKDIR: Không thể tạo thư mục - quyền từ chối lý do cho lỗi này là người dùng bạn đang chạy MKDIR là, không có quyền tạo thư mục mới ở vị trí bạn đã chỉ định. Bạn nên sử dụng lệnh LS trên thư mục cấp cao hơn để xác nhận quyền.the user you're running the mkdir as, doesn't have permissions to create new directory in the location you specified. You should use ls command on the higher level directory to confirm permissions.

Làm cách nào để sửa chữa quyền MKDIR bị từ chối?

[ErrorException] mkdir (): sự cho phép bị từ chối.Điều đó có nghĩa là bạn không có quyền viết trên thư mục dự án của mình.Tạo một thư mục mới, giả sử 'myProject và chạy sudo chmod 777 myProject. Sau đó chuyển sang thư mục' myProject 'và tạo dự án.Create a new folder, say 'myproject and run sudo chmod 777 myproject . Then move to 'myproject' folder and create project.

Làm thế nào tạo thư mục nếu không tồn tại trong PHP?

Phương pháp: File_Exists (): Đây là một hàm sẵn được sử dụng để kiểm tra xem một tệp hoặc thư mục có tồn tại hay không.is_dir (): Nó cũng được sử dụng để kiểm tra xem một tệp hoặc thư mục có tồn tại hay không.MKDIR (): Hàm này tạo ra một thư mục.file_exists(): It is an inbuilt function that is used to check whether a file or directory exists or not. is_dir(): It is also used to check whether a file or directory exists or not. mkdir() : This function creates a directory.

Làm thế nào bạn sẽ tạo một thư mục trong PHP?

Hàm mkdir () được sử dụng để tạo thư mục trong PHP.Nó là một chức năng sẵn có trong PHP.Hàm mkdir () tạo một thư mục mới với tên đường dẫn được chỉ định.Đường dẫn và chế độ được gửi dưới dạng tham số đến hàm mkdir () và nó trả về thành công hoặc sai khi thất bại. is used to create directory in PHP. It is an inbuilt function in PHP. The mkdir() function creates a new directory with the specified pathname. The path and mode are sent as parameters to the mkdir() function and it returns TRUE on success or FALSE on failure.

Chủ đề