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.

Recommended Answers

All 4 Replies

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.