2

i am using wget in php, i want to give a custom name to response file that i receive . here is my wget code .

<?php 

exec('wget  --header= --user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1" --save-cookies 6.txt --keep-session-cookies --post-data="email=myemail@gmail.com&password=pass" http://example.com/login.php 2>&1', $output);
print_r($output);  ?>

when i send wget request, i will receive a file named welcome.php, i will like to rename this file to example.php, how we do this in wget? Thanks

Sandra
  • 21
  • 3
  • Why are you using wget instead of streams or curl functions? Have you checked `curl --help` or he manpage? (hint: look for "output" in the help text) – johannes Jan 22 '16 at 13:48
  • Use the PHP module cURL instead of using wget over console, as it can be dangerous and used to harm you. – Charlotte Dunois Jan 22 '16 at 14:08

1 Answers1

0

i found the way to do this. --output-document=example.php will do this.

<?php 

exec('wget  --header= --user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1" --save-cookies 6.txt --keep-session-cookies --post-data="email=myemail@gmail.com&password=pass" --output-document=example.php http://example.com/login.php 2>&1', $output);
print_r($output);  ?>
Sandra
  • 21
  • 3
  • Note that the --output-document (or -O) option isn't quite the same thing as wget-ing the file and then renaming it. In particular when getting the same file more than once, or getting more than one file at a time. Carefully read the excellent description here: https://www.gnu.org/software/wget/manual/wget.html#Download-Options – sootsnoot Jul 12 '19 at 15:44