Reputation: 3554
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 = 'http://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);
?>
Upvotes: 22
Views: 58910
Reputation: 516
Give permission in to dynamically created file
$upPath = yourpath;
if(!file_exists($upPath))
{
$oldmask = umask(0);
mkdir($upPath, 0777, true);
umask($oldmask);
}
Upvotes: 2
Reputation: 1277
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;
}
Upvotes: 2
Reputation: 3554
we can even ignore *$handle* it will still create the file and copy the content to the $path
<?php
//Get the file
$content = 'http://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);
?>
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 35963
Use the function chmod
chmod
$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
chmod($file, 0777);
Upvotes: 51
Reputation: 29925
You can use chmod() to do this.
e.g. chmod($my_file, 0777);
Upvotes: 0