Create file in php with permission

Hi i have a script which dynamically created a file on my local directory Please tell me how can i give 777 permission to that file right now it is unaccessible in the browser


asked Jan 7, 2013 at 9:30

Create file in php with permission

Rohit GoelRohit Goel

3,3147 gold badges51 silver badges104 bronze badges

3

Use the function chmod
chmod

$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
chmod($file, 0777); 

answered Jan 7, 2013 at 9:32

1

Use chmod() to set file permissions.

answered Jan 7, 2013 at 9:31

use:

private function writeFileContent($file, $content){
   $fp = fopen($file, 'w');
   fwrite($fp, $content);
   fclose($fp);
   chmod($file, 0777);  //changed to add the zero
   return true;
}

answered Dec 5, 2014 at 10:32

Create file in php with permission

Give permission in to dynamically created file

                  $upPath = yourpath;
                    if(!file_exists($upPath)) 
                    {
                        $oldmask = umask(0);
                        mkdir($upPath, 0777, true);
                        umask($oldmask);
                    }  

answered Nov 19, 2015 at 9:40

You can use chmod() to do this.

e.g. chmod($my_file, 0777);

answered Jan 7, 2013 at 9:32

Create file in php with permission

Thomas ClaysonThomas Clayson

29.3k26 gold badges144 silver badges222 bronze badges

set default permission to u r directory (i.e rwx) using setfacl command

ex: setfacl -d -m o::rwx your/directory/path

then any thing u create in that directory it takes rwx permission.

Create file in php with permission

Dhara

4,0932 gold badges34 silver badges69 bronze badges

answered Jan 7, 2013 at 11:06

we can even ignore *$handle* it will still create the file and copy the content to the $path

 

answered Jan 9, 2013 at 10:10

Create file in php with permission

Rohit GoelRohit Goel

3,3147 gold badges51 silver badges104 bronze badges

How can I give permission to a file in PHP?

PHP chmod() Function.
// Read and write for owner, nothing for everybody else. chmod("test.txt",0600);.
// Read and write for owner, read for everybody else. chmod("test.txt",0644);.
// Everything for owner, read and execute for everybody else. chmod("test.txt",0755);.

How do I give PHP permission to 777?

If the operation is for already created file then:.
PHP Syntax. chmod ( string $filename , int $mode );.
Ex: chmod('text.txt', 0777);.
If you are creating a new file dynamically then:.
PHP Syntax. ... .
Ex: mkdir($_SERVER['DOCUMENT_ROOT']. ... .
Hope its clear..

How do I make a file writable in PHP?

PHP is_writable() Function The is_writable() function checks whether the specified filename is writable. Note: The result of this function is cached. Use clearstatcache() to clear the cache.

How do you create a PHP file?

To create a new PHP file within a project:.
In PHP Explorer view, select the Project within which you would like to place the file..
Right-click and select New | PHP File -or- go to File on the Menu Bar and select New | PHP File..
The PHP File creation dialog will be displayed..
Enter the name of the file and click Next..