php - PHP代码片段无法创建文件
问题描述
我有一个 HTML 表单,带有 action="file.php" 和 method="post"
但是这个“file.php”不能创建文件:
<?php
$my_file = 'username.txt';
$handle = fopen($my_file,'w');
foreach($_POST as $variable => $value)
{
if($variable == 'email')
{
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
}
fwrite($handle, "\r\n");
fclose($handle);
exit;
?>
但可能是问题吗?
解决方案
尝试使用它,确保您对文件有写权限。
<?php
$myfile = fopen("username.txt", "w") or die("Unable to open file!");
$txt = (isset($_POST['email'])) ? $_POST['email'] : "";
fwrite($myfile, $txt);
fclose($myfile);
?>
推荐阅读
- php - Docusign 从模板下载文件
- oauth-2.0 - Azure Active Directory 的 OAuth 客户端收到 AADSTS70002:验证凭据时出错
- .net - 使用通过 LINQ 查询的 SQL Server 中的超时异常
- php - Joomla HTML上的MathJax扩展使括号斜体或强调文本
- linux - rmmod时是否需要devm_iounmap,哪个模块使用devm * api?
- angularjs - 量角器角度js
- python - 在 python 3.6 子进程中运行 awk 日期转换
- c - printf - 我可以将所有可变参数作为指针而不是在堆栈上一个接一个地传递吗?
- java - 如何在来自 Java 适配器的响应中返回状态代码 500?
- android - 以相反的顺序显示 ListView(最新的在顶部)并保持 OnScrolling ListView 的顺序