-1
error_reporting(E_ALL); 
ini_set('display_errors','1'); 
if (file_exists('/../_config.php')) { 
    $f = fopen('/../_config.php', 'w') or die($php_errormsg);
    fwrite($f, '<?php');
    fclose($f);
}
else {
    echo 'file doesnt exist';
}

戻り値: なし

_config.php ファイルを確認しましたが、空です。が含まれているはずでした<?php

絶対にエラーはなく、コードはまったく停止しません。

許可関連の問題ですか?私はWindows 7を使用しています。

4

2 に答える 2

1

ファイルへの適切なパスを使用します。

error_reporting(E_ALL); 
ini_set('display_errors','1'); 

$configFile = __DIR__ . '/../config.php';

echo $configFile, "\n";

if (file_exists($configFile)) { 
    $f = fopen($configFile, 'w') or die('cannot open file');
    fwrite($f, '<?php');
    fclose($f);
}
else {
    echo 'file doesnt exist', "\n";
}

代わりに__DIR__使用できますdirname(__FILE__)が、これは古い (死んだ) PHP バージョンでのみ必要です。

于 2013-10-15T21:18:47.690 に答える