Unfortunately, I cannot use either fopen or file_get_contents, so my working script has become a broken one using cURL:
$ch = curl_init(); curl_setopt($ch, C
Set CURLOPT_RETURNTRANSFER to 1 so you get something into $tmp, otherwise curl_exec outputs the csv directly (and before you send the headers). See http://www.php.net/manual/en/function.curl-setopt.php