我试图从同一个文件读写数据,这可能吗?读写同一个文件
这里是我得到阴性结果有:
<?php
$file = fopen("filename.csv", "r") or exit("Unable to open file!");
while (!feof($file)) {
$line = fgets($file);
fwrite($file,$line);
}
fclose($file);
?>
我试图从同一个文件读写数据,这可能吗?读写同一个文件
这里是我得到阴性结果有:
<?php
$file = fopen("filename.csv", "r") or exit("Unable to open file!");
while (!feof($file)) {
$line = fgets($file);
fwrite($file,$line);
}
fclose($file);
?>
你在只读模式打开文件。如果您还想写入文件,请执行以下操作: fopen("filename.csv", "r+")
您以“只读”模式打开文件。请参阅docs。
$file = fopen("filename.csv", "r+") or exit("Unable to open file!");
您需要使用更多'r +'而不是'r'来打开文件。请参阅fopen的文档:http://php.net/manual/en/function.fopen.php
通常您使用模式“r +”打开文件来读取/写入 – 2011-02-04 05:21:51