#!/usr/bin/php -q // WebCopy.php // Chieh Cheng // 2007-06-29 // http://www.CynosureX.com/ // GNU General Public License (GPL) Version 2, June 1991 ini_set ("user_agent", "WebCopy.php; http://www.CynosureX.com/"); function usage ($scriptPath) { $scriptName = basename ($scriptPath); $cwd = getcwd (); echo " Usage: " . $scriptName . " \"URL\" \"file path\"\n"; echo "\n"; echo " Current directory is\n"; echo " " . $cwd . "\n"; echo "\n"; echo " In PHP 4:\n"; echo " You must specify full file path. Or you will\n"; echo " download to this script's directory.\n"; echo "\n"; echo " In PHP 5:\n"; echo " The current directory works properly, so you\n"; echo " will download to the directory that you\n"; echo " currently reside, if you don't specify full\n"; echo " path.\n"; } $args = count ($argv); if ($args == 3) { $url = $argv [1]; $filename = $argv [2]; $handle = fopen ($url, "rb"); if ($handle) { $outFileStream = fopen ($filename, "wb"); while (! feof ($handle)) { $buffer = fread ($handle, 8192); fwrite ($outFileStream, $buffer); } fclose ($outFileStream); fclose ($handle); } else { echo "Cannot open stream to " . $url . "\n"; } } else { usage ($argv [0]); } ?>