Jump to content

force download in php external url


Jeevan25

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

The filename comes from this header:header('Content-Disposition: attachment; filename="downloaded.pdf"');The call to readfile or file_get_contents obviously needs to be the file you actually want to read, not the name of the file you want to save it as.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...