Browse - Programming Tips - How can I do a wget in php?

Date: 2010mar27
Language: php

Q.  How can I do a wget in php?

A.  There are several ways.  You can shell out to wget.
But for normal use here are some ways.

# Just use copy! function fetchUrl1($url, $file) { return copy($url, $file); } # I prefer this one since you can tell if getting the URL failed # there was a permission (etc) problem locally. function fetchUrl2($url, $filename) { if (($s = file_get_contents($url)) === false) return false; return file_put_contents($filename, $s); }
As I said, there are other ways.