随机 PHP txt 创建
Random PHP txt create
我有一个问题。我做了一个小项目,希望能像其他文本粘贴一样保存软件。这是主要的小代码:
fopen("text/$file.txt", "w+");
fwrite($file, $data);
fclose("text/$file.txt");
}
else {
die('No post data to process');
}
?>
问题是它给我这些错误:
Warning: fwrite() expects parameter 1 to be resource, integer given in /home/u257807476/public_html/ready.php on line 8
Warning: fclose() expects parameter 1 to be resource, string given in /home/u257807476/public_html/ready.php on line 10
我不知道为什么。请帮助我!
您使用的 fopen
和 fclose
有误。
试试这个
$fileRes = fopen("test.txt", "w+");
fwrite($fileRes, 'asd');
fclose($fileRes);
另见函数http://php.net/manual/pl/function.file-put-contents.php
file_put_contents
哪个使用起来更简单
Incase 你正在 posting 数据并且你不知道那里有多少参数,那么你可以使用这段代码,这将帮助你将所有 post 参数写在文件中的key+>value形式。
$myFile = "testfile.txt"; // Open File
$fh = fopen($myFile, 'a') or die("can't open file");
$createStar = "****************************** \r\n";
fwrite($fh, $createStar);
$writedate = "Date : ".date('Y-m-d h:i:s');
fwrite($fh, $writedate);
$newLine = "\r\n";
fwrite($fh, $newLine);
$newLine = "\r\n";
fwrite($fh, $newLine);
$postReq1 = "Array( \r\n";
foreach($_REQUEST as $key=>$value)
{
$postReq1.= "[$key] => $value \r\n";
}
$postReq1.= " )";
$PostData = "Response : ".$postReq1;
fwrite($fh, $PostData);
$stringData = "\r\n ****************************** \r\n";
fwrite($fh, $stringData);
close($fh);
我有一个问题。我做了一个小项目,希望能像其他文本粘贴一样保存软件。这是主要的小代码:
fopen("text/$file.txt", "w+");
fwrite($file, $data);
fclose("text/$file.txt");
}
else {
die('No post data to process');
}
?>
问题是它给我这些错误:
Warning: fwrite() expects parameter 1 to be resource, integer given in /home/u257807476/public_html/ready.php on line 8
Warning: fclose() expects parameter 1 to be resource, string given in /home/u257807476/public_html/ready.php on line 10
我不知道为什么。请帮助我!
您使用的 fopen
和 fclose
有误。
试试这个
$fileRes = fopen("test.txt", "w+");
fwrite($fileRes, 'asd');
fclose($fileRes);
另见函数http://php.net/manual/pl/function.file-put-contents.php
file_put_contents
哪个使用起来更简单
Incase 你正在 posting 数据并且你不知道那里有多少参数,那么你可以使用这段代码,这将帮助你将所有 post 参数写在文件中的key+>value形式。
$myFile = "testfile.txt"; // Open File
$fh = fopen($myFile, 'a') or die("can't open file");
$createStar = "****************************** \r\n";
fwrite($fh, $createStar);
$writedate = "Date : ".date('Y-m-d h:i:s');
fwrite($fh, $writedate);
$newLine = "\r\n";
fwrite($fh, $newLine);
$newLine = "\r\n";
fwrite($fh, $newLine);
$postReq1 = "Array( \r\n";
foreach($_REQUEST as $key=>$value)
{
$postReq1.= "[$key] => $value \r\n";
}
$postReq1.= " )";
$PostData = "Response : ".$postReq1;
fwrite($fh, $PostData);
$stringData = "\r\n ****************************** \r\n";
fwrite($fh, $stringData);
close($fh);