I'm using wget in a php script and need to get the name of the file downloaded.
For example, if I try
<?php
system('/usr/bin/wget -q --directory-prefix="./downloads/" http://www.google.com/');
?>
I will get a file called index.html in the downloads directory.
EDIT: The page will not always be google though, the target may be an image or stylesheet, so I need to find out the name of the file that was downloaded.
I'd like to have something like this:
<?php
//Does not work:
$filename = system('/usr/bin/wget -q --directory-prefix="./downloads/" http://www.google.com/');
//$filename should contain "index.html"
?>
Maybe that's some kind of cheating, but why not :
wget should createwget that the download should be made to that fileCheck out the -O option of wget ;-)
For example, running this from the command-line :
wget 'http://www.google.com/' -O my-output-file.html
Will create a file called my-output-file.html.
if your requirement is simple like just getting google.com, then do it within PHP
$data=file_get_contents('http://www.google.com/');
file_put_contents($data,"./downloads/output.html");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With