Jump to content

force download in php external url


Jeevan25
 Share

Recommended Posts

i want the user to bed forced to download when they click a link. This code works fine if the file is in the same server.<?php// We'll be outputting a PDFheader('Content-type: application/pdf');// It will be called downloaded.pdfheader('Content-Disposition: attachment; filename="downloaded.pdf"');// The PDF source is in original.pdfreadfile('original.pdf');?> but what do i do if the file is on another server, like youtube or something?I tried readfile('http://www.domain.com/file.pdf');but that downloads like a 5KB file. Is this possible?

Link to comment
Share on other sites

It's possible to download a 5KB file. Did you check to make sure it's the right file? Does it open? You can use either readfile or file_get_contents to display the file if the fopen wrappers are enabled on the server, or you can also use fopen and fread to output the file.

Link to comment
Share on other sites

Hmm. It should never do that, it shouldn't display the PHP code. If it's displaying the PHP code it sounds more like the server isn't running the PHP script, it's just displaying the code as text. Are you sure the code is running? If you just echo a string, do you see the string or do you see the echo statement? file_get_contents returns a string, so all you're doing here is echoing a string, you shouldn't see the code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...