Jump to content

[SOLVED] PHP Download problems


johnsmith153

Recommended Posts

I want users to download a file:

 

$fileurl = 'excel-file.xlsx';
if(!file) {die('file not found');}
else {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$fileurl");
header("Content-Transfer-Encoding: binary");
readfile($fileurl); }
exit;

 

However:

 

(1) if file not found - ( if(!file) {die('file not found');} ) - it justs attempts to download an empy file, it doesnt show error message

(2) Most importantly, if I have any $_SESSION activity before hand it tries tries to download a html document in the same name as the actual php file - and just wont download the .xlsx I specified. I must have some form of login control with this. (file is located out of public_html)

Link to comment
https://forums.phpfreaks.com/topic/135142-solved-php-download-problems/
Share on other sites

Great. Thanks.

 

Any idea about the other part of my question? It seems very strange:

 

(2) Most importantly, if I have any $_SESSION activity before hand it tries tries to download a html document in the same name as the actual php file - and just wont download the .xlsx I specified. I must have some form of login control with this. (file is located out of public_html)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.