Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mkdir() in php is setting folder permission to 755 But I Need 777?

I am trying to create a folder on my server using php when i set it to 0777 it comes out as 755?

mkdir($create_path, 0777);

Thank you

like image 477
Rickstar Avatar asked Nov 09 '10 14:11

Rickstar


People also ask

How do I give PHP permission to 777?

You can use chmod() to do this.

How do I fix permission denied mkdir?

[ErrorException] mkdir(): Permission denied Create a new folder, say 'myproject and run sudo chmod 777 myproject . Then move to 'myproject' folder and create project. To solve this problem, go into your laravel project, make your public directory writable.

When you create a file using PHP you must place it in a directory with 777 permissions?

In PHP, we aren't able to create a directory with 777 permission because of default umask. The umask is called a user mask or user file creation mask. This is a kind of base permission or default permission given when a new file or folder is created. The default value of umask is generally 022.

What is mkdir in PHP?

The mkdir() function creates a directory specified by a pathname.


3 Answers

Try this:

$old_umask = umask(0);
mkdir($create_path, 0777);
umask($old_umask);

http://php.net/umask

like image 55
ySgPjx Avatar answered Oct 20 '22 11:10

ySgPjx


This really works for me!, you should close now this question!

  1. Create the directory!
  2. Give 777 permissions!

    $estructure = '../files/folderName';
    
    if(!mkdir($estructure, 0777, true)){
        echo "<br/><br/>ERROR: Fail to create the folder...<br/><br/>"; 
    }  else echo "<br/><br/>!! Folder Created...<br/><br/>";
    
    chmod($estructure, 0777);
    
  3. Enjoy it!

like image 21
Ing Guillermo Malagón Avatar answered Oct 20 '22 12:10

Ing Guillermo Malagón


Try this:

<?php
// files will create as -rw-------
umask(0);
// create a file, eg fopen()

chmod('/path/to/directory', 0777);
?>

Reference

like image 43
Zakaria Avatar answered Oct 20 '22 11:10

Zakaria