Jump to content

problem writing to a file


game2002

Recommended Posts

I have an array that I am trying to write to a file.

The array is fine when I print it. But for some reason, the file content doesn't change. And I don't get any error.

here is the code. Thanks for helping.

$zonefile = 'setAdzoneFlag.txt';
print " filename is $zonefile<br>";
if (is_writable($zonefile)) {
    $handle = fopen($zonefile, 'w+') or die("cannot open file $zonefile");;
    
     $fileline = "The zones\r\n";
     
     if (fwrite($handle, $fileline) === FALSE){
print "Error: Unable to write to file:  $zonefile <br>";
die('<br><br>cannot write');	
     }
     
     print " fileline1 is $fileline<br>";
     for ($i = 0; $i < count($groupeZones); $i++)
     {
$fileline = key($groupeZones).",".current($groupeZones)."\r\n";
print " fileline is $fileline<br>";  //data is good

fwrite($handle, $fileline);	
next($groupeZones);
     }
     fclose($handle);   	         
} else 
    echo "The file $filename is not writable";

Link to comment
https://forums.phpfreaks.com/topic/56978-problem-writing-to-a-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.