我已经在PHP中编写了此代码,因为我想练习文件处理。
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<form action = "index.php" method = "get">
Do you want to make a new file (NF), edit a file (EF), or delete a file (DF)?
<input type = "text" name = "FileHandling">
<input type = "submit">
<br/>
</form>
<?php
$FileCommand = $_GET['FileHandling'];
if($FileCommand == 'NF') {
echo "<form action = 'index.php' method = 'get'><br/>";
echo "What is the new file's name?<br/>";
echo "<input type = 'text' name = 'CreateFile' method = 'get'><br/>";
echo "<input type = 'submit'><br/>";
$FileName = $_GET['CreateFile'];
echo $FileName;
if(null !== $FileName) {
echo $FileName;
echo "yes";
$CreateTheFile = fopen($FileName, 'w');
} else {
echo "No file name chosen. ";
}
}
?>
</body>
</html>
但是,选择“ NF”并键入文件名后出现问题。无法创建该文件:
echo $FileName;
if(null !== $FileName) {
echo $FileName;
echo "yes";
$CreateTheFile = fopen($FileName, 'w');
}
尝试使用is_null()
PHP函数获得所需的结果
将您的代码更改为
if(!is_null($FileName)) {
echo $FileName;
echo "yes";
$CreateTheFile = fopen($FileName, 'w');
}
尝试更改此设置
<input type = 'text' name = 'FileName'>
<input type = 'submit' name='CreateFile>
然后是>>
if isset get CreateFile $fileName = $_GET['FileName']; $f = fopen($filename, "w"); fclose($f);
我正在通过电话写这封信,对不起,因为缺少字符,希望您能以正确的方式写它