Ответ 1
Используйте функцию chmod
chmod
$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
chmod($file, 0777);
Привет у меня есть скрипт, который динамически создал файл в моем локальном каталоге. Скажите, пожалуйста, как я могу дать 777 разрешение на этот файл, сейчас он недоступен в браузере
<?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);
?>
Используйте функцию chmod
chmod
$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
chmod($file, 0777);
Используйте chmod()
, чтобы установить права доступа к файлам.
использование:
private function writeFileContent($file, $content){
$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
chmod($file, 0777); //changed to add the zero
return true;
}
Разрешить доступ к динамически создаваемому файлу
$upPath = yourpath;
if(!file_exists($upPath))
{
$oldmask = umask(0);
mkdir($upPath, 0777, true);
umask($oldmask);
}
Вы можете использовать chmod(), чтобы сделать это.
например. chmod($my_file, 0777);
установите default permission
в каталог u r (т.е. rwx
), используя setfacl command
ex: setfacl -d -m o::rwx your/directory/path
то любая вещь, которую вы создаете в этом каталоге, требует разрешения rwx
.
мы можем даже игнорировать * $handle *, он будет создавать файл и . содержимое $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);
?>