When I Download my file, it do not display all the details of the data. but when I changed my choices for example I change the date, it works fine and it display all the details.
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($this->_filepath).'.csv');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($this->_filepath));
readfile($this->_filepath);
exit();
is it a problem of the memory ?
Related
I am trying to create a file (works), zip a file (works), and download. But when I put it in the order I think is correct I get a warning saying headers already sent
My code is:
//TOP Writes to file -this works
$handle=fopen('db_backup.sql','w+');
fwrite($handle,$end);
fclose($handle);
//Creates zip -this works
$zip =array('db_backup.sql');
create_zip($zip,'db_backup.zip',true);
ob_clean();
flush();
//Download the zip get the headers already sent message
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=db_backup.zip');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize('db_backup.zip'));
readfile('db_backup.zip');
unlink($zip_file);
But if I move headers to TOP I do not get the message. But the zip is empty!
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=db_backup.zip');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize('db_backup.zip'));
//TOP Writes to file -this works
$handle=fopen('db_backup.sql','w+');
fwrite($handle,$end);
fclose($handle);
//Creates zip -this works
$zip =array('db_backup.sql');
create_zip($zip,'db_backup.zip',true);
ob_clean();
flush();
//Download the zip get the headers already sent message
readfile('db_backup.zip');
unlink($zip_file);
i want to create a download pdf file, but its always damaged
i had try this code in other function its working correctly but in this function the downloaded file is corrupt
source and downloaded file has same size its 3.899
this is my code before :
if (file_exists($dir)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($dir).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($dir));
readfile($dir);
exit;
}
and i had try this code too for this issue :
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $length);
set_time_limit(0);
readfile($file);
exit;
i think the problem is in file size,
my code is work corretly in size under 1Mb but i dont know how to change max download size, i had try to search in php.ini but i cant find
====> update
i had try to change file to smaller size file (below 1Mb) but its still damaged
I have a code:
$name = "jeffrey.epub"; //for naming only
$file = "test/cover/cabang.epub"; //the real file to be downloaded
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($name).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
but upon having the download file, it came out corrupted.i also change the header('Content-Type: application/octet-stream'); to header('Content-Type: application/epub+zip'); but still it was corrupted, i was wondering what is the problem that the file is being corrupted
I need to download a file in XLS & XLSX format, I tried Many Way but it is not working.
My download code is as follows:
$file = "Reports.xlsx";
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
Both i Tried :
header('Content-type: application/octet-stream'); - not working
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - not working
For Xls:
header("Content-Type: application/vnd.ms-excel; charset=UTF-8;"); - Working for Xls
How do I put a link to open a pdf in pdf?
I have a code below which does not work
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
It just shows the link to download and does not generate my file to download.