942,959 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 72505
  • PHP RSS
Apr 16th, 2007
0

wget into php

Expand Post »
Is there anyway I can type wget command into a php and that will download file directly from another server to my own server?
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
desiguru is offline Offline
63 posts
since Aug 2006
Apr 16th, 2007
0

Re: wget into php

Click to Expand / Collapse  Quote originally posted by desiguru ...
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 Syntax (Toggle Plain Text)
  1. <?php
  2. $foo = system('wget http://www.myserver.com/file.txt ~',$output);
  3. ?>
pty
Reputation Points: 64
Solved Threads: 39
Posting Pro
pty is offline Offline
530 posts
since Oct 2005
Apr 16th, 2007
0

Re: wget into php

Click to Expand / Collapse  Quote originally posted by desiguru ...
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.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Dec 17th, 2010
0
Re: wget into php
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ctsjoe is offline Offline
1 posts
since Dec 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Wampserver Web Address
Next Thread in PHP Forum Timeline: html form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC