0

Is there anyway I can type wget command into a php and that will download file directly from another server to my own server?

4
Contributors
3
Replies
9
Views
10 Years
Discussion Span
Last Post by ctsjoe
0

Is there anyway I can type wget command into a php and that will download file directly from another server to my own server?

You can run wget by invoking it via the shell as shown above. This however requires that the configuration on your server allows PHP to execute shell commands.

You can however use the regular PHP functions to achive what you want to do with wget.
These are called the Stream Functions.
http://www.php.net/stream

They range from the simple functions such as:

// retrieve the file into a string
$file = file_get_contents('http://example.com/file.ext');

// retrieve the file into an array containing each line
$linesArray = file('http://example.com/file.ext');

to a bit lower level functions such as fopen() and fsockopen() that allow a bit more flexibility.

The only restriction on the stream functions is the ability to use the HTTP wrapper for PHP Streams. This is defined in php.ini, called allow_url_fopen.

0

I came from Google and would like to note to those looking for the same solution I was, in terms of text at least, also consider using the cURL functions that can be extended into PHP.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.