Page 1 of 1
saving a pdf file from web
Posted: Sun Jul 26, 2009 10:30 pm
by Mehnaz
Hi
I have some an array of some pdf links like this
$filename ="
http://www.cdc.gov/nchs/data/ad/ad389.pdf";
I want to use pdftotext on it. But for this I think I need to save these files on my system. Please give me any clue how can I do this. ie. how I can save thiese files temporarly . A piece of code of would be highly appreciated.
Thanks in advance
Mehnaz
Re: saving a pdf file from web
Posted: Mon Jul 27, 2009 11:05 am
by McInfo
Use
file_get_contents() to read the file from the remote server. Then use
file_put_contents() to save the contents to a file on your server. If you want the saved file to have the same name as the original, use
basename().
Edit: This post was recovered from search engine cache.
Re: saving a pdf file from web
Posted: Mon Jul 27, 2009 11:13 am
by jackpf
If they're on another domain I think curl would be a better option. I'm not sure if allow url fopen affects file_get_contents()...
Re: saving a pdf file from web
Posted: Mon Jul 27, 2009 12:39 pm
by McInfo
I tested my solution with the given PDF. I can personally guarantee that it works.
Edit: This post was recovered from search engine cache.
Re: saving a pdf file from web
Posted: Mon Jul 27, 2009 1:40 pm
by jackpf
But you may have url fopen turned on, whereas many shared hosts do not.
Anyway, the only way to find out is for the op to test it

Re: saving a pdf file from web
Posted: Mon Jul 27, 2009 4:32 pm
by Mehnaz
Thanks very much
I used file_get_contents() and file_put_contents() in this way
Code: Select all
$filename = "http://www.cdc.gov/nchs/data/ad/ad389.pdf";
$content = file_get_contents($filename);
$pdffilename = "temp.pdf";
file_put_contents($pdffilename, $content);
and it works perfectly.