Downloads, headers and binary data

From: Date: Fri, 19 Jan 2001 08:38:48 +0000
Subject: Downloads, headers and binary data
Groups: php.general 
Request: Send a blank email to php-general+get-35586@lists.php.net to get a copy of this message
Hi. I'm trying to write a script to download a mp3 file. I did this: $filesize=filesize($filename); header("Content-disposition: attachment;filename=".basename($filename)); header("Content-type: application/octetstream"); header("Content-Transfer-Encoding: binary"); header("Pragma: no-cache"); header("Expires: 0"); header("Content-Length: $filesize"); readfile($filename,$filesize); I began with the first two headers but the problem is that the script works fine with text files but I get shorter files than the originals with mp3s, so I added the rest trying to solve the problem. So I tryied $fp=fopen($filename,"r"); fread($fp,filesize($filename)); fclose($fp); and $fp=fopen($filename,"r"); fpassthru($fp); None of above worked. But I tryied using the php.exe and I got exactly what I want. So, perhaps it is a problem with the headers. I tryied both Netscape and IE, and also diferents content-type (audio/mpeg). Anyone has ideas? Juan Germano droctulft@yifan.net

« previous php.general (#35586) next »