homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

script running locally, how to upload a file

 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:



 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:




...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"];
$filename = $_FILES['userfile']['tmp_name'];
print "Nothing to do!";exit();
// process $var1,$var2,$filename here

(where 'userfile' is the name of the file field in the HTML form)


 1:16 pm on Mar 12, 2009 (gmt 0)

thanks! I think that's a good idea.


 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]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved