Use drupal_realpath(), to help ensure that the ftruncate() will work.

Looks like the "temporary://" stream wrapper that Drupal includes does
not support ftruncate()...  Resolving the URI to a file works, though.