I was building a file download Class for my CMS in PHP, at a time I noticed it outputs files in a different Encoding format. I tried with readfile, file_get_contents,fread but all seem to be doing the same thing. It"s like something that has to do with output buffering.
An example image file in png format I downloaded using the script seems to work after changing the Encoding using notepad++ from UTF to ASCII
These are the steps i've taken so far:
$mime = http::get_file_mime();
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Transfer-Encoding: binary');
header('Transfer-Encoding: binary');
header('Content-Description: File Transfer');
header('Content-Encoding: chunked');
header('Connection: closed');
@readfile($this->file);
I did fread:
$file = fopen($this->file,'r');
$read = fread($file,filesize($this->file));
print($read);
I did file_get_contents();
$read = file_get_contents($this->file);
print($read);
All of these steps sends the file to the download dialog. But it doesnt output the file as it is. And this affects any file i try to download with the script.
What am i doing wrong ?