...

View Full Version : File corrupt when downloaded from php



JustBlaze
08-28-2007, 07:01 AM
Not exactly sure how to go about fixing this so I
decided to ask here.

If i go to /song.mp3 it downloads and plays just fine
but if i use this php code.


<?php
$file = 'song.mp3';
_Download("".$file, $file);
function _Download($f_location,$f_name){
header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header('Content-Type: audio/mpeg');
header('Content-Length: ' . filesize($f_location));
header('Content-Disposition: attachment; filename=' . basename($f_name));
readfile($f_location);
}
?> Gotta remove some of the code once I get it working correctly...

The song downloads but is all skippy and corrupted
sounding. Anyone know how to fix this?

-Thanks
JustBlaze

meth
08-28-2007, 07:53 AM
Change the content-type header to "application/octet-stream" and test. If the stream is buggered, I'd say php errors are being written to the file.

z7server
08-29-2007, 08:32 AM
I use for file load :


$data = file_get_contents($f_location);
echo $data;


Titti
Textures (http://textures.z7server.com)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum