如何在不删除所有现有数据的情况下写入文本文件?我试过这个
$txt = 'srge';
$file = fopen('text.txt','w');
fwrite($file,$txt);
Run Code Online (Sandbox Code Playgroud)
但它不起作用,一切都在耳边
注意:这只有在你有适当的权限时才有效,test.txt否则它会说
权限被拒绝(不合适会导致这个)
这里我们使用:
1. a这是用于附加这将在文件末尾附加文本。
2. 而不是 w, flagw用于写入,它将写入文件而不关心您在该文件中的现有数据。
PHP代码:
<?php
ini_set('display_errors', 1);
$txt = 'srge';
$file = fopen('text.txt','a');
fwrite($file,$txt);
Run Code Online (Sandbox Code Playgroud)