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
saving a pdf file from web
Moderator: General Moderators
Re: saving a pdf file from web
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.
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 3:59 pm, edited 1 time in total.
Re: saving a pdf file from web
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
I tested my solution with the given PDF. I can personally guarantee that it works.
Edit: This post was recovered from search engine cache.
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 3:59 pm, edited 1 time in total.
Re: saving a pdf file from web
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
Anyway, the only way to find out is for the op to test it
Re: saving a pdf file from web
Thanks very much
I used file_get_contents() and file_put_contents() in this way
and it works perfectly.
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);