How to run wget from php so that output gets displayed in the browser window?
views:
205answers:
2
+3
A:
You can just use file_get_contents instead. Its much easier.
echo file_get_contents('http://www.google.com');
If you have to use wget, you can try something like:
$url = 'http://www.google.com';
$outputfile = "dl.html";
$cmd = "wget -q \"$url\" -O $outputfile";
exec($cmd);
echo file_get_contents($outputfile);
codaddict
2010-03-27 07:07:18
-1 sorry but this does not answer the question at all.
Max
2010-03-27 07:10:31
+1 It's a perfectly acceptable alternative to trying to run a system command which may be disallowed in the first place.
jasonbar
2010-03-27 07:12:35
@Johan: the answer was edited and the second example was added after my comment, so please calm down, ok?
Max
2010-03-27 08:46:47
@Max: Sorry missed that (I removed my comment since it's irrelevant)
Johan
2010-03-28 07:41:17
+3
A:
The exec function can be used to run wget. I've never used wget for more then simple file downloads but you would use whatever arguments you give to wget to make it output the file contents. The second parameter/argument of exec will be an array, and this array will be filled line by line with the output of wget.
So you would have something like:
<?php
exec('wget http://google.com/index.html -whateverargumentisusedforoutput', $array);
echo implode('<br />', $array);
?>
The manual page for exec probably explains this better: http://php.net/manual/en/function.exec.php
Chris Clarke
2010-03-27 07:19:33