0

我有小代码。

total_request.txt 是文本文件,内容值 =1

$file = 'total_request.txt';
$count = file_get_contents( $file );
echo $a = $count + 1;  
file_put_contents( $file, $a ); 

代码输出值:2

但文件 total_request.txt 的内容为 3。我想在运行此文件 php.ini 时自动递增 1。

我的代码有什么问题?

4

1 回答 1

0

您可能希望以附加模式打开文件:

<?php
$fp = fopen('data.txt', 'a');//opens file in append mode  
fwrite($fp, ' this is additional text ');  
fwrite($fp, 'appending data');  
fclose($fp);
?>

我希望它可以帮助你。

问候。

于 2020-08-05T03:48:10.813 回答