johnsmith153 Posted December 2, 2008 Share Posted December 2, 2008 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 More sharing options...
gevans Posted December 2, 2008 Share Posted December 2, 2008 Your not checking the actuall file in line 2; <?php if(!file($fileurl)) die('file not found'); else { //carry on } ?> Link to comment https://forums.phpfreaks.com/topic/135142-solved-php-download-problems/#findComment-703884 Share on other sites More sharing options...
johnsmith153 Posted December 2, 2008 Author Share Posted December 2, 2008 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) Link to comment https://forums.phpfreaks.com/topic/135142-solved-php-download-problems/#findComment-703887 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.