954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

wget into php

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

desiguru
Junior Poster in Training
63 posts since Aug 2006
Reputation Points: 10
Solved Threads: 1
 
Is there anyway I can type wget command into a php and that will download file directly from another server to my own server?
<?php
  $foo = system('wget http://www.myserver.com/file.txt ~',$output);
?>
pty
Posting Pro
530 posts since Oct 2005
Reputation Points: 64
Solved Threads: 39
 
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:
[HTML]

// 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');

[/HTML]

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.

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

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.

ctsjoe
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You