I wrote this function, originated from qa_write_blob_file():
function qa_update_blob_file($blobid, $content, $format)
/*
Update the on-disk file for blob $blobid with $content and $format. Returns true if the write succeeded, false otherwise.
*/
{
$written = false;
$directory = qa_get_blob_directory($blobid);
if (is_dir($directory))
{
$filename = qa_get_blob_filename($blobid, $format);
$file = fopen($filename, 'wa+'); // xb would create a new file, however, we replace it
if(is_resource($file))
{
if(fwrite($file, $content)>=strlen($content))
$written = true;
fclose($file);
if(!$written)
unlink($filename);
}
}
return $written;
}