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
<?php //Get the file $content = '//xxx.xxx.com.mx/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/b/r/bridal-shoes1.jpg '; $content1 = explode('/', $content); $end = end($content1); echo $end; //print_r($content1[12]); //Store in the filesystem. $my_file = $end; $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file); //implicitly creates file $path = '/var/www/'.$end; copy($content, $path); ?>asked Jan 7, 2013 at 9:30
Rohit GoelRohit Goel
3,3147 gold badges51 silver badges104 bronze badges
3
Use the function chmod
chmod
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
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
Thomas ClaysonThomas Clayson
29.3k26 gold badges144 silver badges223 bronze badges
set default permission to u r directory (i.e rwx) using setfacl command
ex: setfacl -d -m o::rwx your/directory/paththen any thing u create in that directory it takes rwx 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
<?php //Get the file $content = '//dev.aviesta.com.mx/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/b/r/bridal-shoes1.jpg '; $content1 = explode('/', $content); $end = end($content1); echo $end; //print_r($content1[12]); //Store in the filesystem. $my_file = $end; $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file); //implicitly creates file $path = '/var/www/'.$end; copy($content, $path); ?>answered Jan 9, 2013 at 10:10
Rohit GoelRohit Goel
3,3147 gold badges51 silver badges104 bronze badges