Forum Moderators: coopster

Message Too Old, No Replies

Save pdf file

Save a pdf file from a url to the server.

         

Sathallrin

7:00 pm on Dec 5, 2005 (gmt 0)

10+ Year Member



My php page recieves a URL that goes to a pdf file. When I have this link, I would like the script to retrieve the file and save it on the server. I can't seem to find a function that works to do this.

Any Ideas?

ashishp

7:13 pm on Dec 5, 2005 (gmt 0)

10+ Year Member



You could always piggyback on wget or fetch...

<?
$e = `wget $_GET[url]`;
echo '$_GET[url] retrieved!';
?>

Of course, you'd need to add all kinds of security checks etc...but i hope you get the idea..

Sathallrin

7:50 pm on Dec 5, 2005 (gmt 0)

10+ Year Member



Thanks, but I couldn't get wget to work with it. However, I was able to get it to work by using this:

$handle = fopen("temp\\test.pdf", "wb");
if (fwrite($handle, file_get_contents($URL)) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);