PHP Force Download Causing 0 Byte Files

Posted by Alex on Stack Overflow See other posts from Stack Overflow or by Alex
Published on 2011-01-16T15:06:57Z Indexed on 2011/01/16 15:53 UTC
Read the original article Hit count: 205

Filed under:
|
|

Hey,

I'm trying to force download files from my web server using PHP. I'm not a pro in PHP but I just can't seem to get around the problem of files downloading in 0 bytes in size.

CODE:

$filename = "FILENAME...";

header("Content-type: $type");
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');
set_time_limit(0);
readfile($file);

Can anybody help? Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about download