gpt4 book ai didi

php - fwrite() 期望参数 1 是资源,c 中给出的字符串 ://

转载 作者:行者123 更新时间:2023-12-03 09:19:26 24 4
gpt4 key购买 nike

我正在使用最新版本的 php..并且我陷入了这个错误

Warning: fwrite() expects parameter 1 to be resource, string given in c:\ this error shows me 6 times

Warning: fclose() expects parameter 1 to be resource, string given in // this error reapeat only one time.

我试图获取最后一行的最后一个 id,但我遇到了这个错误..这是我的 php 代码:

<?php
include_once('../../fucrenzione.php');
/*
$codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$codeAlphabet.= "abcdefghijklmnopqrstuvwxyz";
$codeAlphabet.= "0123456789";*/
$filename ="data.txt" or die("Unable to open file!");
$line="";
fopen($filename, 'a+');
for($i=0;$i<=5;$i++ ){

$va=rand(1,20);
$re= rand(2,50);
$data = [
'val1' => $va,
'val2' => $re,
'body' => getToken(10),
'Id'=> $i,
'timestamp' => time()
];

/* echo "<pre>".*/$line = serialize($data);
$line .= "\n";
fwrite($filename, $line);

}
fclose($filename);
?>

我也尝试使用fputs(),但我仍然收到该错误。

最佳答案

该错误告诉您问题所在。 fopen() 返回一个资源:

$handle = fopen($filename, 'a+');

然后 fwrite() 期望第一个参数是该资源:

fwrite($handle, $line);

此外,我认为 or die("Unable to open file!");fopen() 行而不是赋值行上会更好。

关于php - fwrite() 期望参数 1 是资源,c 中给出的字符串 ://,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34187674/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com