2016-10-09 19 views
0

PHPでfopenを使ってファイルを開こうとしていません。PHPはファイルを読み取ることができません

 $db_ausgaenge = "statuseing.php"; 
     $dout = fopen($db_ausgaenge, "x+"); 
     print $dout; 
     print(shell_exec('whoami')); 
     print(shell_exec('pwd')); 
     print(shell_exec('id')); 
     fwrite($dout, $out); 
     fclose($dout); 

Warning: fopen(statuseing.php): failed to open stream: File exists in /var/www/html/zufallsgenerator.php on line 33 

私は以下の項目をチェックする:statuseing.php 0777用

  • のchmod
  • 所有者がスクリプトは、ユーザWWWデータとして
  • を実行している
  • 用グランドWWWのデータをWWW-データであり、
  • グループは、uid = 33(www-データ)gid = 33(www-データ)groups = 33(www-データ)
  • です.pwdは期待通りに/ var/www/htmlです
  • スクリプトが開こうとしているパスが正しいです
  • php.iniのopenbase dirがphpinfo()に追加されましたが、/ var/www/htmlが追加されましたが、phpは気にしません。デーモンリロードして変更systemctl何経由のapache2を再起動した後=/var/www/htmlと設定/

open_basedirの

、のphpinfo()は、設定で指定されたパスを示しませんでした。 init 6を使ってシステムを再起動しても効果はありませんでした。

答えて

1

statuseing.phpはすでに存在しています。

http://php.net/manual/en/function.fopen.php)のマニュアルを参照してください - xまたはX +モードの開口部は言う:Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE

+0

は 'W +' にする方法を開いて、そして今それがうまく働いているスワップ。この問題に言及してくれてありがとう。 –

+0

ここではあなたの問題ではありませんでしたが、個人的には、fopen()または同様の関数を呼び出す前に、常にファイルへのフルパスを設定する方が好きです。 –

0

をチェックアウトし、あなたのシナリオに応じて適切なモードを見つけるために、この:

$db_ausgaenge = __DIR__."/statuseing.php"; 
    $dout = fopen($db_ausgaenge, "w+"); 
    print(shell_exec('whoami')); 
    print(shell_exec('pwd')); 
    print(shell_exec('id')); 
    fwrite($dout, $out); 
    fclose($dout); 

$db_ausgaenge = __DIR__."/statuseing.php"; 
    $dout = fopen($db_ausgaenge, "a+"); // x+ will throw error cuz it tries to open existing file, thx to: bluegman991 (; 
    print(shell_exec('whoami')); 
    print(shell_exec('pwd')); 
    print(shell_exec('id')); 
    fwrite($dout, $out); 
    fclose($dout); 

またはあなたは、データ使用w+を追加する前に、ファイルを切り捨てるしたい場合また、いくつかの検査を行う:

1)の空き容量チェック:あなたは、そのファイルを編集することができた場合df -h
2)チェック:nano /var/www/html/statuseing.php

関連する問題