| script running locally, how to upload a file
|
wheel

msg:3866546 | 6:59 pm on Mar 9, 2009 (gmt 0) | I have a script that runs on my webserver that takes a file for input, along with some other data. It crunches some numbers, then emails an output file. I want to automate this with a large number of input files and run it locally. How do I pass an input file as a variable from a shell script? i.e. on my regular web page I have a standard html input form where I can browse/upload the file that then pulls that file up when I hit submit - how do I reference that on a shell script? I know for the other variables I can just do this as my script line: [192.168.0.1...]
|
dmorison

msg:3868189 | 5:36 pm on Mar 11, 2009 (gmt 0) | I think you'll need to handle it completely differently - as the browser upload mechanism is a very specific part of the HTTP protocol. Shouldn't be that difficult however, I'd only envisage changing from: [192.168.0.1...] to: [192.168.0.1...] ...and then the script - if you wanted to maintain the ability to upload files via the browser; would just check for the presence of $_GET["filename"] in preference to using the uploaded file; for example: $var1 = $_GET["var1"]; $var2 = $_GET["var2"]; if (isset($_GET["filename"])) { $filename = $_GET["filename"]; } elseif($_FILES['userfile']['tmp_name']) { $filename = $_FILES['userfile']['tmp_name']; } else { print "Nothing to do!";exit(); } // process $var1,$var2,$filename here
(where 'userfile' is the name of the file field in the HTML form)
|
wheel

msg:3868783 | 1:16 pm on Mar 12, 2009 (gmt 0) | thanks! I think that's a good idea.
|
coopster

msg:3868823 | 2:13 pm on Mar 12, 2009 (gmt 0) | Don't forget that PHP can accept command line values as well.
if (isset($_SERVER['argv'])) { unset($_SERVER['argv'][0]); // contains <file>, as in -f switch $argv = array_values($_SERVER['argv']); if (empty($argv)) { print "Usage: php -f <file> [OPTIONS] <value1 [value2 [...]]>\n\n"; // document command line values here return false; } // process command line request } Using PHP from the command line [php.net]
|
|
|