We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,530 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

file download problem

Hi

I need help regarding file download.

$url="http://".$_SERVER.$_SERVER;

$id = strrchr($url,"/");
$id= substr($id,1,strlen($id));

retrieving name of the pdf from url

header('Content-disposition: attachment; filename='.$id);
header('Content-type: application/pdf');
readfile($id);

code for downloading file

but it is not working?

So i need help from you guys.

Thanks in advance.

3
Contributors
4
Replies
12 Hours
Discussion Span
1 Year Ago
Last Updated
5
Views
adityamadhira
Newbie Poster
23 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
pritaeas
Posting Prodigy
Moderator
9,316 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,467
Skill Endorsements: 86

But it generating binary content of the file.....not working.

adityamadhira
Newbie Poster
23 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

The Content-Type header must be sent before the Content-Disposition header.

edwinhermann
Junior Poster
142 posts since Sep 2009
Reputation Points: 67
Solved Threads: 29
Skill Endorsements: 2

my code

$file= $_GET;

header('Content-Description: File Transfer');
header('Content-type: application/pdf');
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));
ob_clean();
flush();
readfile($file);
exit;

even though i am getting binary content.

adityamadhira
Newbie Poster
23 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1171 seconds using 2.69MB