Im trying to read and write to/from the same file, is this possible?
Here is what I am getting negative results with:
<?php
$file = fopen("filename.csv", "r") or exit("Unable to open file!");
while (!feof($file)) {
$line = fgets($file);
fwrite($file,$line);
}
fclose($file);
?>
You're opening the file in read-only mode. If you want to write to the file as well, do
fopen("filename.csv", "r+")
You'll need to open the file with more 'r+' instead of just 'r'. See the documentation for fopen: http://php.net/manual/en/function.fopen.php
You opened the file in "read only" mode. See the docs.
$file = fopen("filename.csv", "r+") or exit("Unable to open file!");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With