Dave's Brain

Browse - programming tips - php wget url

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.
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: