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。
使用正确的文件路径:
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";
}
您可以使用dirname(__FILE__)
而不是__DIR__
但这仅在过时的(死)PHP 版本中是必需的。
检查您的PHP文件权限是否设置为666,并检查目录的权限,确保其设置为777