32
4.3
URL OF PICTURES AND OTHER SUPPORTING FILES
Sometimes a script based webpage will need to link to other supporting files such as graphics
and images. A directory name
scripts
on the root level of the URL is provided to give the user a
location for supporting files.
In reality,
/scripts
is simply a symbolic link to the standard pool of scripts in which all scripts are
stored. Therefore, the user may simply store images or other supporting files like he/she would
scripts and link to them with the URL /scripts/user/
file
.
The example in Figure 12, shows the script for a webpage that links to an image names
logo.jpg
.
The user must upload both this script and the image
logo.jpg
for the webpage created by this
script to display properly.
Figure 12 Example Linking to a User Image
4.4
PASSING ARGUMENTS TO THE SCRIPT
Arguments are passed to the script via URL by simply adding name/value pairs to the URL. For
example:
/cgi-bin/script.cgi?script=
myscript.lua
&arg1=val1&arg2=val2
In the above example, the script receives the arguments
val1
and
val2
. The labels (
arg1
and
arg2
) are discarded before running the script therefore they may be any identifier. Also, because
the labels are discarded, the order of the arguments is important as the script has no way to
identify an argument other than the order in which it was received.
Arguments are received by the script in the same manner is if the script was called from the
command line. When a script is called, a Lua table named
arg
is defined and populated with the
arguments. Table item
arg[0]
contains the name of the script. The arguments are placed in
arg[1]
,
arg[2]
and so forth in the order in which they appear in the URL.
Figure 13 illustrates the Lua source code required to retrieve the arguments. In this example, the
table
arg
is printed to the webpage as the index followed by the argument.
print([[
<html>
<head>
<title>An HTML Page</title>
</head>
<body>
<img src="/scripts/user/logo.jpg" alt="logo" />
</body>
</html>
]])