6

Is there any way to test if writing to a file was successfully accomplished? I need a method to obtain the end of time of a writing operation. If so to trigger a callback function.

3
  • 1
    fwrite() returns the number of bytes written, or FALSE on error. Sep 17, 2012 at 13:28
  • How do you write in file? Show us your code, please. And as a short answer, yes, it is.
    – Leri
    Sep 17, 2012 at 13:29
  • 1
    There's too many ways to answer this question. Show some code
    – Mike B
    Sep 17, 2012 at 13:36

1 Answer 1

12

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.

You can use filemtime() to get the last modification time of a file.

3
  • 2
    Nice man - why don't you post opened PLB's comment as an extra answer? ))) Sep 17, 2012 at 13:31
  • 1
    @webbandit I don't follow what you mean
    – Samuel
    Sep 17, 2012 at 13:41
  • @Samuel eah sure you don't ;) Sep 17, 2012 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.