File download is not working

Hi,

I’m using php 5.3 and Apache 2.2 in Linux OS. The file download is not working. I have used below code. Please help! The same code was working in local pc while developed. The local pc was php 5.3, apach2.2 and windows 7.

		header('Content-Description: File Transfer');
		//Below line is replace by force-download because this was not working when downloaded from web server
		//header('Content-Type: application/octet-stream');
		header("Content-Type: application/force-download");
		//header('Content-Disposition: attachment; filename='.basename($file));
		header('Content-Disposition: attachment; filename='.$actualfilename); //fetched filename from database
		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($file));
		ob_clean();
		flush();
		readfile($file);

I just test it and it is working for me.

PHP Version 5.2.17

Thanks for quick response. The code mentioned above is implemented in Annual Project. Can you please try below link and download the excel?

http://www.annualproject.com/sourcecode/?sourcecode&pcode=4f61dc4f8a9e8470367655

I downloaded it and there is no file name associated with the download. Viewing it with excel shows no content.

It’s very strange… when I try to open it, it saves file with name as “0” and I cannot open it. I will try it again.

Check your

header(‘Content-Disposition: attachment; filename=’.$actualfilename); //fetched filename from database

make sure actualfilename is the name of the file name you want to use. Note that you can use any name.