_tina_ Posted November 14, 2009 Share Posted November 14, 2009 Hi, I have a page, you click on a link and are brought to a new page which forces a PDF download. The problem is that the file starts to download and the page doesn't even load an stays on the current page. So I click the link, the file starts but I stay on the current page. Is there a way around this? Thanks in advance. This is the page that forces the download which never loads. header("Content-type: application/pdf"); header("'Content-Disposition: attachment; filename=\"email.pdf\""); readfile($file); include("header.php"); //sleep(5); ?> <br> <p> Page content.. </p> Quote Link to comment Share on other sites More sharing options...
ram4nd Posted November 14, 2009 Share Posted November 14, 2009 $file is not declared read http://php.net/manual/en/function.header.php Quote Link to comment Share on other sites More sharing options...
_tina_ Posted November 15, 2009 Author Share Posted November 15, 2009 $file is declared, I just didn't copy that part of my code. I have read the header function page, not really sure whats going on here. Anybody have any ideas? $file is not declared read http://php.net/manual/en/function.header.php Quote Link to comment Share on other sites More sharing options...
alex3 Posted November 15, 2009 Share Posted November 15, 2009 The problem is you're trying to serve two different types of content on one page. The headers you're sending to the web browser basically say "I'm sending you a PDF file, and I'm going to start outputting it now". After this declaration, you've got HTML, which isn't what the browser is expecting (and rightly so, because you've told it otherwise). So the browser downloads the file, and behaves like it would if you were linking directly to a zip file or something. Try it, create a little HTML page with an anchor link to something that the browser can't display natively (so no images, audio/movie files etc.) and you'll see exactly the same behaviour: the browser starts the download, but stays on the page with the link. Quote Link to comment Share on other sites More sharing options...
_tina_ Posted November 15, 2009 Author Share Posted November 15, 2009 Thanks for that Alex, that makes a lot of sense. I guess I'll have to find an alternate way to achieve this. Thanks again. The problem is you're trying to serve two different types of content on one page. The headers you're sending to the web browser basically say "I'm sending you a PDF file, and I'm going to start outputting it now". After this declaration, you've got HTML, which isn't what the browser is expecting (and rightly so, because you've told it otherwise). So the browser downloads the file, and behaves like it would if you were linking directly to a zip file or something. Try it, create a little HTML page with an anchor link to something that the browser can't display natively (so no images, audio/movie files etc.) and you'll see exactly the same behaviour: the browser starts the download, but stays on the page with the link. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.