20

こんにちは私は自分のローカルディレクトリにファイルを動的に作成するスクリプトを持っていますブラウザでアクセスできない今、そのファイルに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);

 ?>
4

7 に答える 7

47

関数chmodchmodを使用し
ます

$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
chmod($file, 0777); 
于 2013-01-07T09:32:36.397 に答える
3

chmod()ファイルのアクセス許可を設定するために使用します。

于 2013-01-07T09:31:51.840 に答える
2

使用する:

private function writeFileContent($file, $content){
   $fp = fopen($file, 'w');
   fwrite($fp, $content);
   fclose($fp);
   chmod($file, 0777);  //changed to add the zero
   return true;
}
于 2014-12-05T10:32:14.433 に答える
2

動的に作成されたファイルにアクセス許可を与える

                  $upPath = yourpath;
                    if(!file_exists($upPath)) 
                    {
                        $oldmask = umask(0);
                        mkdir($upPath, 0777, true);
                        umask($oldmask);
                    }  
于 2015-11-19T09:40:50.820 に答える
0

これを行うには、 chmod()を使用できます。

例えばchmod($my_file, 0777);

于 2013-01-07T09:32:11.277 に答える
0

default permissionを使用してurディレクトリ(つまりrwx)に設定setfacl command

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

次に、そのディレクトリに作成するものはすべてrwx許可が必要です。

于 2013-01-07T11:06:21.247 に答える
0

* $ 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);

     ?>
于 2013-01-09T10:10:38.267 に答える