Jeevan25 Posted September 19, 2007 Share Posted September 19, 2007 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 More sharing options...
justsomeguy Posted September 19, 2007 Share Posted September 19, 2007 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 More sharing options...
Jeevan25 Posted September 19, 2007 Author Share Posted September 19, 2007 I tried echo (file_get_contents('http://domain.com/file.pdf')); but its going to the script that is called and outputting its contents. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 19, 2007 Share Posted September 19, 2007 What do you mean, it's displaying the contents of the PHP script that includes the file_get_contents function? Link to comment Share on other sites More sharing options...
Jeevan25 Posted September 19, 2007 Author Share Posted September 19, 2007 yeah instead of displaying the pdf file contents, its displaying contents of the file that forces the user to download the file. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 19, 2007 Share Posted September 19, 2007 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 More sharing options...
Jeevan25 Posted September 20, 2007 Author Share Posted September 20, 2007 the thing is i want the user to download an external file, but with the file name that i set. i know they can rename while saving, but i want the default to be mine. you know how? thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted September 20, 2007 Share Posted September 20, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.