This is my code:
$zplHandle = fopen($target_file,'w');
fwrite($zplHandle, $zplBlock01);
fwrite($zplHandle, $zplBlock02);
fwrite($zplHandle, $zplBlock03);
fclose($zplHandle);
When will the file be saved? Is it immediately after writing to it or after closing it?
I am asking this because I have Printfil listening to files in a folder and prints any file that is newly created. If PHP commits a save immediately after fwrite
, I may run into issues of Printfil not capturing the subsequent writes.
Thank you for the help.
The fwrite function writes up to count items, of size length each, from buffer to the output stream . The file pointer associated with stream (if there's one) is incremented by the number of bytes fwrite writes. If stream is opened in text mode, each line feed is replaced with a carriage return-line feed pair.
fwrite() function in PHP The fwrite() function writes to an open file. It returns the number of bytes written on success, whereas returns False on failure.
fwrite() returns the number of bytes written, or FALSE on error. Check whether fwrite() returns false and you'll know that the write succeeded. Be careful to use the === comparison operator instead of the == operator when checking if the returned value is false.
fwrite() does not exactly overwrite by using fseek(). Instead, there are several cases: if the open permissions was 'r' then writing is an error.
the file will be saved on fclose. if you want to put the content to the file before, use fflush().
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