Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining form FILE and TEXT input 1

Status
Not open for further replies.

lagerplease

Technical User
Dec 15, 2001
38
GB
I'm using a form to send data and files to a PERL script. In the FORM tag I've specified ENCTYPE=MULTIPART/FORM-DATA but it then doesn't seem to recognise any of the text input fields. I've added ACCEPT=TEXT/PLAIN, IMAGE/JPEG and it still doesn't work. When I get rid of all the above tags it recognises the text fields but the files are uploaded with a 0 file size.

Can you only submit text OR files using a single HTML form? Surely not!

Any help would be appreciated.
 
... let me elaborate. Specifically, it's ignoring the hidden input fields which force the script to perform different functions.
 
I'm guessing you're trying to create an upload file form and perl script.

rather than trying to find where you're going wrong I'll post what works for me. I haven't tested what I've posted it but it should be pretty self explanatory.

any problems / further questions let me know

cheers and good luck

Joe


##### PERL SCRIPT ###################################
#
# requires a number of parameters set in the form:
#
# DIR: the directory on the webserver the files are to placed into
# REDIRECT: where to go to after the successful upload
# FILE($): the file(s) to be uploaded. Named FILE1, FILE2 etc
# NEW($): corresponding new file name if required. Named NEW1, NEW2 etc
#
#
#####################################################

use CGI;
$query = new CGI;
my $whatDir = $query->param('DIR');
$Data = "$whatDir";

# Set all the other environment variables
@good_extensions = ('gif','jpg','JPG','jpeg','mpeg','bmp','txt','rpt','doc','png','csv','xls','pdf','html','htm','css','zip','tar.gz','xml','zip','ZIP','srg','SRG');
@bad_extensions = ('exe');
my $redirect = $query->param('REDIRECT');
$max_size = 1000000;
$max_num_files = 10;

# Start the serious stuff from here
use CGI;
$max_num_files ||= 1;
$Data ||= $ENV{'DOCUMENT_ROOT'};
undef @bad_extensions if @good_extensions;
for(my $a = 1; $a <= $max_num_files; $a++) {
my $req = new CGI;
if($req->param(&quot;FILE$a&quot;)) {

# pick up new file name if requested
my $new = $req->param(&quot;NEW$a&quot;);
$new =~ s/ +/\_/g;
my $newname = $new;
$newname =~ s/^.*(\\|\/)//;

# pick up the file for download
my $file = $req->param(&quot;FILE$a&quot;);
#$file =~ s/ +/\_/g;
my $filename = $file;
$filename =~ s/^.*(\\|\/)//;

# get the new file extension
my $extension = $filename;
$extension =~ s/([^*]|\n)*\b\.//g;

# join the new file name with the reuired extension
my $wholename = join &quot;.&quot;,$newname,$extension;

# give the new string if new filename is defined
$filename = $wholename if $newname;
my $proceed_type = 0;

# validate the extension from the good extensions bit
if(@good_extensions) {
foreach(@good_extensions) {
my $ext = $_;
$ext =~ s/\.//g;
if($filename =~ /\.$ext$/) {
$proceed_type = 1;
last;
}
}
unless($proceed_type) {
push(@was_not_good_type, $filename);
}
}

# for bad extensions get names for later
elsif(@bad_extensions) {
$proceed_type = 1;
foreach(@bad_extensions) {
my $ext = $_;
$ext =~ s/\.//g;
if($filename =~ /\.$ext$/) {
$proceed_type = 0;
last;
}
}
unless($proceed_type) {
push(@was_a_bad_type, $filename);
}
} else {
$proceed_type = 1;
}

# either download or not and add names to arrays
if($proceed_type) {
if(open(OUTFILE, &quot;>$Data/$filename&quot;)) {
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);
push(@file_did_save, $filename);
} else {
push(@did_not_save, $filename);
}
}

# file too big error
if($max_size) {
if((-s &quot;$Data/$filename&quot;) > ($max_size * 1024)) {
push(@was_too_big, $filename);
unlink(&quot;$Data/$filename&quot;);
}
}
}
}

# the redirect bit
print &quot;Pragma: no-cache\n&quot;;

print &quot;Content-type: text/html\n\n&quot;;
print &quot;<HEAD><TITLE>Upload Results</TITLE></HEAD><BODY>&quot;;
print &quot;<TABLE>\n&quot;;
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:11pt;font-weight: bold;\&quot;>Upload Results</TD></TR>\n&quot;;
print &quot;</TABLE>\n&quot;;
print &quot;<hr>\n&quot;;
print &quot;<TABLE>\n&quot;;

# if print saved then imform
if(@file_did_save) {
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:10.5pt;font-weight: bold;\&quot;>You have uploaded file(s):</TD></TR>\n&quot;;
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:8.5pt\&quot;>\n&quot;;
print join(&quot;<BR>&quot;, @file_did_save);
print &quot;<BR><BR></TD></TR>\n&quot;;
}
# if non specified file type the show
if(@was_not_good_type) {
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:10.5pt;font-weight: bold;\&quot;>The following file(s) were not stored as their file extensions have not been specified for download:</TD></TR>\n&quot;;
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:8.5pt\&quot;>@was_not_good_type</TD></TR>\n&quot;;
}
# if defined illegal file type
if(@was_a_bad_type) {
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:10.5pt;font-weight: bold;\&quot;>The following file(s) were not stored as their file extension are on the list of extensions not permitted for upload:</TD></TR>\n&quot;;
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:8.5pt\&quot;>@was_a_bad_type</TD></TR>\n&quot;;
}
# if file too big
if(@was_too_big) {
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:10.5pt;font-weight: bold;\&quot;>The following file(s) were not stored as their file size exceeded the maximum file size of $max_size Kb.:</TD></TR>\n&quot;;
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:8.5pt\&quot;>@was_too_big</TD></TR>\n&quot;;
}
# if file wasn't saved
if(@did_not_save) {
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:10.5pt;font-weight: bold;\&quot;>The following file(s) were not stored because the program could not open their destination file:</TD></TR>\n&quot;;
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:8.5pt\&quot;>@did_not_save</TD></TR>\n&quot;;
# other errors
if(!@file_did_save) {
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:8.5pt\&quot;>NOTE: Check to ensure that the \$Data variable reflects the correct<BR>absolute path to the directory these files should be stored in.</TD></TR>\n&quot;;
}
}
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:10.5pt;font-weight: bold;\&quot;>Your destination directory was:</TD></TR>\n&quot;;
print &quot;<TR><TD style=\&quot;font-family:helvetica;font-size:8.5pt\&quot;>$whatDir</TD></TR>\n&quot;;
print &quot;<TR><TD> </TD></TR>\n&quot;;


## redirect if specified
if($redirect) {
print &quot;<script language='javascript'>\n&quot;;
print &quot;setTimeout('document.location=\&quot;$redirect\&quot;',1500);\n&quot;;
print &quot;</script>\n&quot;;
}

##### SAMPLE HTML FORM ###################################

<HTML>
<HEAD>

<SCRIPT language=&quot;javascript&quot;>
function CheckAndDo() {
// any confirmation / validation you need to do on the form here!
var v1=1;
}
</SCRIPT>

<TITLE>TRS Upload</TITLE>
</HEAD>


<FORM name=&quot;Post_form&quot; METHOD=&quot;POST&quot; ACTION=&quot;/cgi-bin/mako/upload.sh&quot; ENCTYPE=&quot;multipart/form-data&quot; onSubmit=&quot;return CheckAndDo()&quot;>

<INPUT TYPE=&quot;hidden&quot; NAME=&quot;DIR&quot; VALUE=&quot;/$full_data_directory_path&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;REDIRECT&quot; VALUE=&quot;/$full_redirection_html_page_path&quot;>

<TABLE class=&quot;pageheader&quot; cellspacing=&quot;0&quot;>
<TR>
<TD ID=&quot;Phhead&quot; class=&quot;PHh&quot;>Upload Files</TD>
</TR>
</TABLE>
<HR>

<TABLE class=&quot;pageheader&quot; cellspacing=&quot;0&quot;>
<TR>
<TD ID=&quot;PHbody&quot; class=&quot;PHb&quot;>File 1:</TD>
<TD><INPUT TYPE=&quot;FILE&quot; NAME=&quot;FILE1&quot; size=50 maxlength=80><INPUT TYPE=&quot;hidden&quot; NAME=&quot;NEW1&quot; VALUE=&quot;new_file1&quot;></TD>
</TR>
<TR>
<TD ID=&quot;PHbody&quot; class=&quot;PHb&quot;>File 2:</TD>
<TD><INPUT TYPE=&quot;FILE&quot; NAME=&quot;FILE2&quot; size=50 maxlength=80><INPUT TYPE=&quot;hidden&quot; NAME=&quot;NEW2&quot; VALUE=&quot;new_file2&quot;></TD>
</TR>

<TABLE class=&quot;pageheader&quot; cellspacing=&quot;0&quot;>
<TR>
<TD><INPUT TYPE=&quot;submit&quot; VALUE=&quot;Upload&quot;></INPUT></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
 
Thanks for the details Joe. It looks very similar to what I'm already using. I'm starting to think I've got something wrong within my HTML as the script I'm using is completely ignoring the hidden input fields when I use the ENCTYPE parameter.

Have you got this working in a live situation where I could have a quick peek?

Thanks again.

Phil Wills
 
unfortunately I'm working on an intranet so no public access available I'm afraid. It is used on a daily basis though.

Checklist/ thoughts. (sorry if these are obvious)

1. ENCTYPE set correctly.
2. The params are named correctly consistently between form and script.
3. The inputs are not disabled and are all on the same form and they are of the correct type (ie type file for files, text /hidden etc)
4. you're posting or getting correctly (the above example POSTs)

Check that the form inputs are being submitted - try a javascript alert using the onsubmit - '<FORM... onsubmit=&quot;alert(form.inputname.value)&quot; >'. If these are being submitted then its a perl issue.

Can you not pick up any query params at all ? You could try looping through in the script to collect all sent params

If you post your html / perl I can have a look though I'm no expert...

Joe.
 
I've tried one of your ideas above and come to the conclusion that this is absolutely crazy and unexplainable. I've attached the original script below and I've amended it to execute a new script called test.cgi once the form has been submitted (ignore all the commenting out in the 'adddetails' subroutine - this bit is still in the testing stage). I've also attached the test.cgi script.

If you run the original script as it is you will notice that it passes all the parameters. If you run it with the ENCTYPE parameter included you will notice that it doesn't pass anything.

I'm bloody flummoxed!!!


### Original script ###

#!/usr/bin/perl

########################################################################
# #
# ADMIN_ADD.CGI (developed for #
# Copyright 2003 Dotquake Web Services, all rights reserved #
# Web: Email: info@dotquake.com #
# #
# This program is provided for sole use on the web site for which it #
# was developed and must not be used elsewhere or redistributed in any #
# form without the express permission of the copyright holder #
# #
# Version history: #
# 1.0 - 02/01/03: Conception #
# #
########################################################################

$stockfile = &quot;../htdocs/vstock.dat&quot;;
$vmakesfile = &quot;../htdocs/vmakes.dat&quot;;
$reffile = &quot;../htdocs/reference.dat&quot;;

print &quot;Content-type: text/html\n\n&quot;;

if ($ENV{'REQUEST_METHOD'} eq &quot;GET&quot;)
{
@argpairs = split(/&/, $ENV{'QUERY_STRING'});
}
else
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@argpairs = split(/&/, $buffer);
}

foreach $dataline (@argpairs)
{
($argname, $argvalue) = split(/=/, $dataline);
$argvalue =~ tr/+/ /;
$argvalue =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;
$argvalue =~ s/<!--(.|\n)*-->//g;
$argvalue =~ s/<([^>]|\n)*>//g;
$form{$argname} = $argvalue;
}

if ($form{scriptaction} eq &quot;adddetails&quot;)
{
&adddetails;
}

open (REFFILE, &quot;$reffile&quot;);
@reffile = <REFFILE>;
close (REFFILE);

foreach $dataline (@reffile)
{
chomp $dataline;
($reference) = split(/\|/, $dataline);
}

$reference = sprintf(&quot;%04d&quot;, $reference);

print &quot;<html>\n&quot;;
print &quot;<head>\n&quot;;
print &quot;<meta http-equiv=\&quot;Content-Type\&quot; content=\&quot;text/html; charset=iso-8859-1\&quot;>\n&quot;;
print &quot;<meta name=\&quot;Author\&quot; content=\&quot;Dotquake Web Services - info\@dotquake.com\&quot;>\n&quot;;
print &quot;<meta name=\&quot;Description\&quot; content=\&quot;MN Car Sales - Pre-owned cars from £300 upwards\&quot;>\n&quot;;
print &quot;<meta name=\&quot;Keywords\&quot; content=\&quot;car, sales, warranty, part exchange, bodywork repair, valet\&quot;>\n&quot;;
print &quot;<link rel=\&quot;stylesheet\&quot; href=\&quot;../style.css\&quot; type=\&quot;text/css\&quot;>\n&quot;;
print &quot;<script language=\&quot;Javascript\&quot; src=\&quot;../admin_add.js\&quot; type=\&quot;text/javascript\&quot;></script>\n&quot;;
print &quot;<title>MN Car Sales</title>\n&quot;;
print &quot;</head>\n&quot;;
print &quot;<body bgcolor=\&quot;#F0F8FF\&quot; onLoad=\&quot;document.forms.add.make.focus()\&quot;>\n&quot;;
print &quot;<table border=\&quot;0\&quot; cellpadding=\&quot;5\&quot; cellspacing=\&quot;0\&quot; width=\&quot;100%\&quot; background=\&quot;../background.jpg\&quot;>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; valign=\&quot;top\&quot; nowrap><img border=\&quot;0\&quot; src=\&quot;../spacer.gif\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;><img border=\&quot;0\&quot; src=\&quot;../spacer.gif\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;><img border=\&quot;0\&quot; src=\&quot;../mncslogo.gif\&quot; alt=\&quot;MN Car Sales\&quot; width=\&quot;148\&quot; height=\&quot;77\&quot;></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot; align=\&quot;right\&quot; valign=\&quot;top\&quot;><p><b><font face=\&quot;Verdana, Arial\&quot; size=\&quot;3\&quot;>· Pre-owned cars from £300 upwards<br>· Finance & warranties available<br>· Part exchanges welcomed<br>· All types of vehicle purchased for cash</font></b></p></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;</table>\n&quot;;
print &quot;<table border=\&quot;0\&quot; cellpadding=\&quot;3\&quot; cellspacing=\&quot;0\&quot; width=\&quot;100%\&quot;>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td colspan=\&quot;4\&quot;><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;center\&quot; valign=\&quot;top\&quot; nowrap background=\&quot;../menubarback.jpg\&quot;>\n&quot;;
print &quot;<p><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><b>SITE MENU</b><br><br></font>\n&quot;;
print &quot;<font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><b>\n&quot;;
print &quot;<a href=\&quot;../home.html\&quot; title=\&quot;Return to MN Car Sales home page\&quot;>· HOME PAGE ·</a><br>\n&quot;;
print &quot;<a href=\&quot;vehicles.cgi\&quot; title=\&quot;View our range of pre-owned vehicles\&quot;>· OUR VEHICLES ·</a><br>\n&quot;;
print &quot;<a href=\&quot;../vsearch.shtml\&quot; title=\&quot;Search for a specific vehicle\&quot;>· VEHICLE SEARCH ·</a><br>\n&quot;;
print &quot;<a href=\&quot;../partexchange.html\&quot; title=\&quot;Details of our part exchange services\&quot;>· PART EXCHANGE ·</a><br>\n&quot;;
print &quot;<a href=\&quot;../warranties.html\&quot; title=\&quot;Details of our comprehensive warranties\&quot;>· WARRANTIES ·</a><br>\n&quot;;
print &quot;<a href=\&quot;../finance.html\&quot; title=\&quot;Details of our financing services\&quot;>· FINANCE ·</a><br>\n&quot;;
print &quot;<a href=\&quot;../contact.html\&quot; title=\&quot;Contact or locate MN Car Sales\&quot;>· CONTACT US ·</a></b></font></p>\n&quot;;
print &quot;</td>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; style=\&quot;border-right: 3px double #000000\&quot;><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
print &quot;<td width=\&quot;1%\&quot;><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
print &quot;<td width=\&quot;97%\&quot; valign=\&quot;top\&quot;>\n&quot;;
print &quot;<table border=\&quot;0\&quot; cellpadding=\&quot;3\&quot; cellspacing=\&quot;0\&quot; width=\&quot;100%\&quot;>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td background=\&quot;../menubarback.jpg\&quot;><b><i><font face=\&quot;Verdana, Arial\&quot; size=\&quot;4\&quot;>Add New Vehicle</font></i></b></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td valign=\&quot;top\&quot;>\n&quot;;
print &quot;<p><font face=\&quot;Verdana, Arial\&quot; size=\&quot;2\&quot;>Please use the form below to enter the details for the new vehicle which you wish to add to stock.</font></p>\n&quot;;
#print &quot;<form method=\&quot;POST\&quot; name=\&quot;add\&quot; action=\&quot;test.cgi\&quot; enctype=\&quot;multipart/form-data\&quot; onSubmit=\&quot;return checkForm()\&quot;>\n&quot;;
print &quot;<form method=\&quot;POST\&quot; name=\&quot;add\&quot; action=\&quot;test.cgi\&quot; onSubmit=\&quot;return checkForm()\&quot;>\n&quot;;
print &quot;<input type=\&quot;hidden\&quot; name=\&quot;scriptaction\&quot; value=\&quot;adddetails\&quot;><input type=\&quot;hidden\&quot; name=\&quot;reference\&quot; value=\&quot;$reference\&quot;>\n&quot;;
print &quot;<table border=\&quot;0\&quot; cellpadding=\&quot;3\&quot; cellspacing=\&quot;0\&quot; width=\&quot;100%\&quot;>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Vehicle reference:</font></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot;><font face=\&quot;Verdana, Arial\&quot; size=\&quot;2\&quot;><b>$reference</b></font></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Make of vehicle:</font></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot;><select size=\&quot;1\&quot; name=\&quot;make\&quot;><option selected>Please select from list</option>&quot;;

open (VMAKESFILE, &quot;$vmakesfile&quot;);
@vmakesfile = <VMAKESFILE>;
close (VMAKESFILE);

foreach $dataline (@vmakesfile)
{
chomp $dataline;
($vmake) = split(/\|/, $dataline);

print &quot;<option>$vmake</option>&quot;;
}

print &quot;</select></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Model:</font></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot;><input type=\&quot;text\&quot; name=\&quot;model\&quot; size=\&quot;20\&quot;></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Other:</font></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot;><input type=\&quot;text\&quot; name=\&quot;other\&quot; size=\&quot;20\&quot;><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><i> i.e., 2.0 DL, GTi, etc.</i></font></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Year of manufacture:</font></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot;><input type=\&quot;text\&quot; name=\&quot;year\&quot; size=\&quot;5\&quot; maxlength=\&quot;4\&quot;><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><i> Please use four figure years</i></font></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Engine size:</font></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot;><input type=\&quot;text\&quot; name=\&quot;engine\&quot; size=\&quot;5\&quot;><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><i> Enter numeric values only</i></font></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Colour:</font></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot;><input type=\&quot;text\&quot; name=\&quot;colour\&quot; size=\&quot;20\&quot;></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; valign=\&quot;top\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Description:</font></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot;><textarea name=\&quot;details\&quot; rows=\&quot;8\&quot; cols=\&quot;50\&quot;></textarea></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Price:</font></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot;><input type=\&quot;text\&quot; name=\&quot;price\&quot; size=\&quot;8\&quot;><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><i> Enter numeric values only with no pound sign</i></font></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Ownership:</font></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot;><select size=\&quot;1\&quot; name=\&quot;prefix\&quot;><option>MNAA</option><option selected>MNCS</option></select><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><i> Select 'MNCS' for MN Car Sales vehicles, 'MNAA' for all others</i></font></td>\n&quot;;
print &quot;</tr>\n&quot;;
#print &quot;<tr>\n&quot;;
#print &quot;<td colspan=\&quot;2\&quot;><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
#print &quot;</tr>\n&quot;;
#print &quot;<tr>\n&quot;;
#print &quot;<td colspan=\&quot;2\&quot;><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><b>IMPORTANT:</b> Before you can add this new vehicle to stock you will need to have created the required images for displaying on the site.<br><br>File <b>mncs$reference.jpg</b> (main image) should be <b>300 x 240</b> pixels in size.<br>File <b>mnct$reference.jpg</b> (thumbnail) should be <b>100 x 80</b> pixels in size.<br><br>These images should be named <b>exactly</b> as specified here (i.e. all in lower case) and the file locations on your computer where they have been saved should be specified in the boxes below.</font></td>\n&quot;;
#print &quot;</tr>\n&quot;;
#print &quot;<tr>\n&quot;;
#print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Main image file location:</font></td>\n&quot;;
#print &quot;<td width=\&quot;99%\&quot;><input type=\&quot;file\&quot; name=\&quot;mainimage\&quot; size=\&quot;40\&quot;></td>\n&quot;;
#print &quot;</tr>\n&quot;;
#print &quot;<tr>\n&quot;;
#print &quot;<td width=\&quot;1%\&quot; align=\&quot;right\&quot; nowrap><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;>Thumbnail image file location:</font></td>\n&quot;;
#print &quot;<td width=\&quot;99%\&quot;><input type=\&quot;file\&quot; name=\&quot;thumbimage\&quot; size=\&quot;40\&quot;></td>\n&quot;;
#print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot;><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot;><input type=\&quot;submit\&quot; value=\&quot;Add details\&quot; name=\&quot;submit\&quot; ID=\&quot;submit\&quot;></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;</table>\n&quot;;
print &quot;</form>\n&quot;;
print &quot;</td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;</table>\n&quot;;
print &quot;</td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr><td colspan=\&quot;4\&quot;><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;</table>\n&quot;;
print &quot;<table border=\&quot;0\&quot; cellpadding=\&quot;5\&quot; cellspacing=\&quot;0\&quot; width=\&quot;100%\&quot; background=\&quot;../background.jpg\&quot;>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td align=\&quot;right\&quot; nowrap><p><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><b>MN Car Sales, Proprietor: Mark Norton<br>St Andrews Yard, Willeys Avenue, Exeter, EX2 8EP<br>Enquiries: <a href=\&quot;mailto:enquiries\@mncarsales.co.uk\&quot; title=\&quot;Send email to MN Car Sales\&quot;>enquiries\@mncarsales.co.uk</a><br>Tel: 01392 276728, mobile: 07974 382416 (24 hr)</b></font></p></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;</table>\n&quot;;
print &quot;<p align=\&quot;right\&quot;><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot; color=\&quot;#808080\&quot;><i>\n&quot;;
print &quot;<script language=\&quot;Javascript\&quot; type=\&quot;text/javascript\&quot;><!--\n&quot;;
print &quot;copyright()\n&quot;;
print &quot;--></script>\n&quot;;
print &quot;<br>Best viewed at 800 x 600 pixels with browser version 4.0 or later<br>Design, programming & maintenance by <a href=\&quot; title=\&quot;Dotquake Web Services\&quot; target=\&quot;_blank\&quot;><img src=\&quot;../dwslogo.gif\&quot; border=\&quot;0\&quot; align=\&quot;absmiddle\&quot; width=\&quot;24\&quot; height=\&quot;14\&quot;></a> <a href=\&quot; title=\&quot;Dotquake Web Services\&quot; target=\&quot;_blank\&quot;>Dotquake Web Services</a></i></font></p>\n&quot;;
print &quot;</body>\n&quot;;
print &quot;</html>&quot;;

sub adddetails
{
# $form{details} =~ tr/\n/ /;
#
# open (STOCKFILE, &quot;>$stockfile&quot;);
# flock (STOCKFILE, 2);
# seek (STOCKFILE, 0, 0);
#
# foreach $dataline (@stockfile)
# {
# chomp $dataline;
# ($reference, $make, $model, $other, $year, $engine, $colour, $details, $price, $prefix) = split(/\|/, $dataline);
#
# if ($reference eq $form{reference})
# {
# print STOCKFILE &quot;$reference\|$form{make}\|$form{model}\|$form{other}\|$form{year}\|$form{engine}\|$form{colour}\|$form{details}\|$form{price}\|$form{prefix}\|\n&quot;;
# }
# else
# {
# print STOCKFILE &quot;$dataline\n&quot;;
# }
# }
#
# flock (STOCKFILE, 8);
# close (STOCKFILE);

# open (THUMBIMAGE, &quot;>../htdocs/images/mnct$form{reference}.jpg&quot;);
# binmode THUMBIMAGE;
#
# while (read(&quot;$form{thumbimage}&quot;, $buffer, 1024))
# {
# print THUMBIMAGE $buffer;
# }
#
# close THUMBIMAGE;

print &quot;<html>\n&quot;;
print &quot;<head>\n&quot;;
print &quot;<meta http-equiv=\&quot;Content-Type\&quot; content=\&quot;text/html; charset=iso-8859-1\&quot;>\n&quot;;
print &quot;<meta name=\&quot;Author\&quot; content=\&quot;Dotquake Web Services - info\@dotquake.com\&quot;>\n&quot;;
print &quot;<meta name=\&quot;Description\&quot; content=\&quot;MN Car Sales - Pre-owned cars from £300 upwards\&quot;>\n&quot;;
print &quot;<meta name=\&quot;Keywords\&quot; content=\&quot;car, sales, warranty, part exchange, bodywork repair, valet\&quot;>\n&quot;;
print &quot;<link rel=\&quot;stylesheet\&quot; href=\&quot;../style.css\&quot; type=\&quot;text/css\&quot;>\n&quot;;
print &quot;<script language=\&quot;Javascript\&quot; src=\&quot;../admin_add.js\&quot; type=\&quot;text/javascript\&quot;></script>\n&quot;;
print &quot;<title>MN Car Sales</title>\n&quot;;
print &quot;</head>\n&quot;;
print &quot;<body bgcolor=\&quot;#F0F8FF\&quot;>\n&quot;;
print &quot;<table border=\&quot;0\&quot; cellpadding=\&quot;5\&quot; cellspacing=\&quot;0\&quot; width=\&quot;100%\&quot; background=\&quot;../background.jpg\&quot;>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; valign=\&quot;top\&quot; nowrap><img border=\&quot;0\&quot; src=\&quot;../spacer.gif\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;><img border=\&quot;0\&quot; src=\&quot;../spacer.gif\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;><img border=\&quot;0\&quot; src=\&quot;../mncslogo.gif\&quot; alt=\&quot;MN Car Sales\&quot; width=\&quot;148\&quot; height=\&quot;77\&quot;></td>\n&quot;;
print &quot;<td width=\&quot;99%\&quot; align=\&quot;right\&quot; valign=\&quot;top\&quot;><p><b><font face=\&quot;Verdana, Arial\&quot; size=\&quot;3\&quot;>· Pre-owned cars from £300 upwards<br>· Finance & warranties available<br>· Part exchanges welcomed<br>· All types of vehicle purchased for cash</font></b></p></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;</table>\n&quot;;
print &quot;<table border=\&quot;0\&quot; cellpadding=\&quot;3\&quot; cellspacing=\&quot;0\&quot; width=\&quot;100%\&quot;>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td colspan=\&quot;4\&quot;><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; align=\&quot;center\&quot; valign=\&quot;top\&quot; nowrap background=\&quot;../menubarback.jpg\&quot;>\n&quot;;
print &quot;<p><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><b>SITE MENU</b><br><br></font>\n&quot;;
print &quot;<font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><b>\n&quot;;
print &quot;<a href=\&quot;../home.html\&quot; title=\&quot;Return to MN Car Sales home page\&quot;>· HOME PAGE ·</a><br>\n&quot;;
print &quot;<a href=\&quot;vehicles.cgi\&quot; title=\&quot;View our range of pre-owned vehicles\&quot;>· OUR VEHICLES ·</a><br>\n&quot;;
print &quot;<a href=\&quot;../vsearch.shtml\&quot; title=\&quot;Search for a specific vehicle\&quot;>· VEHICLE SEARCH ·</a><br>\n&quot;;
print &quot;<a href=\&quot;../partexchange.html\&quot; title=\&quot;Details of our part exchange services\&quot;>· PART EXCHANGE ·</a><br>\n&quot;;
print &quot;<a href=\&quot;../warranties.html\&quot; title=\&quot;Details of our comprehensive warranties\&quot;>· WARRANTIES ·</a><br>\n&quot;;
print &quot;<a href=\&quot;../finance.html\&quot; title=\&quot;Details of our financing services\&quot;>· FINANCE ·</a><br>\n&quot;;
print &quot;<a href=\&quot;../contact.html\&quot; title=\&quot;Contact or locate MN Car Sales\&quot;>· CONTACT US ·</a></b></font></p>\n&quot;;
print &quot;</td>\n&quot;;
print &quot;<td width=\&quot;1%\&quot; style=\&quot;border-right: 3px double #000000\&quot;><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
print &quot;<td width=\&quot;1%\&quot;><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
print &quot;<td width=\&quot;97%\&quot; valign=\&quot;top\&quot;>\n&quot;;
print &quot;<table border=\&quot;0\&quot; cellpadding=\&quot;3\&quot; cellspacing=\&quot;0\&quot; width=\&quot;100%\&quot;>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td background=\&quot;../menubarback.jpg\&quot;><b><i><font face=\&quot;Verdana, Arial\&quot; size=\&quot;4\&quot;>Add New Vehicle</font></i></b></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td valign=\&quot;top\&quot;>\n&quot;;
print &quot;<p><font face=\&quot;Verdana, Arial\&quot; size=\&quot;2\&quot;>The details for the new vehicle with reference number <b>$form{reference} ($form{make} $form{model})</b>, detailed below, have been successfully added and all relevant files have been uploaded and updated.</font></p>\n&quot;;
print &quot;<p><font face=\&quot;Verdana, Arial\&quot; size=\&quot;2\&quot;>Please click <a href=\&quot;admin_add.cgi\&quot; title=\&quot;Add another new vehicle\&quot;>here</a> to add another new vehicle, <a href=\&quot;admin_amend.cgi?method=POST&reference=$form{reference}\&quot; title=\&quot;Amend details for this vehicle\&quot;>here</a> to amend the details for this vehicle, or continue to navigate the site using the contents menu on the left of the screen.</font></p>\n&quot;;
print &quot;</td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;</table>\n&quot;;
print &quot;</td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;<tr><td colspan=\&quot;4\&quot;><img src=\&quot;../spacer.gif\&quot; border=\&quot;0\&quot; width=\&quot;8\&quot; height=\&quot;8\&quot;></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;</table>\n&quot;;
print &quot;<table border=\&quot;0\&quot; cellpadding=\&quot;5\&quot; cellspacing=\&quot;0\&quot; width=\&quot;100%\&quot; background=\&quot;../background.jpg\&quot;>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td align=\&quot;right\&quot; nowrap><p><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><b>MN Car Sales, Proprietor: Mark Norton<br>St Andrews Yard, Willeys Avenue, Exeter, EX2 8EP<br>Enquiries: <a href=\&quot;mailto:enquiries\@mncarsales.co.uk\&quot; title=\&quot;Send email to MN Car Sales\&quot;>enquiries\@mncarsales.co.uk</a><br>Tel: 01392 276728, mobile: 07974 382416 (24 hr)</b></font></p></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;</table>\n&quot;;
print &quot;<p align=\&quot;right\&quot;><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot; color=\&quot;#808080\&quot;><i>\n&quot;;
print &quot;<script language=\&quot;Javascript\&quot; type=\&quot;text/javascript\&quot;><!--\n&quot;;
print &quot;copyright()\n&quot;;
print &quot;--></script>\n&quot;;
print &quot;<br>Best viewed at 800 x 600 pixels with browser version 4.0 or later<br>Design, programming & maintenance by <a href=\&quot; title=\&quot;Dotquake Web Services\&quot; target=\&quot;_blank\&quot;><img src=\&quot;../dwslogo.gif\&quot; border=\&quot;0\&quot; align=\&quot;absmiddle\&quot; width=\&quot;24\&quot; height=\&quot;14\&quot;></a> <a href=\&quot; title=\&quot;Dotquake Web Services\&quot; target=\&quot;_blank\&quot;>Dotquake Web Services</a></i></font></p>\n&quot;;
print &quot;</body>\n&quot;;
print &quot;</html>&quot;;

exit;
}

### New test.cgi script ###

#!/usr/bin/perl

print &quot;Content-type: text/html\n\n&quot;;

if ($ENV{'REQUEST_METHOD'} eq &quot;GET&quot;)
{
@argpairs = split(/&/, $ENV{'QUERY_STRING'});
}
else
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@argpairs = split(/&/, $buffer);
}

foreach $dataline (@argpairs)
{
($argname, $argvalue) = split(/=/, $dataline);
$argvalue =~ tr/+/ /;
$argvalue =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;
$argvalue =~ s/<!--(.|\n)*-->//g;
$argvalue =~ s/<([^>]|\n)*>//g;
$form{$argname} = $argvalue;
}

print &quot;<html>\n&quot;;
print &quot;<head>\n&quot;;
print &quot;<title>Upload Test</title>\n&quot;;
print &quot;</head>\n&quot;;
print &quot;<body>\n&quot;;
print &quot;reference = <b>$form{reference}</b><br>\n&quot;;
print &quot;make = <b>$form{make}</b><br>\n&quot;;
print &quot;model = <b>$form{model}</b><br>\n&quot;;
print &quot;other = <b>$form{other}</b><br>\n&quot;;
print &quot;year = <b>$form{year}</b><br>\n&quot;;
print &quot;engine = <b>$form{engine}</b><br>\n&quot;;
print &quot;colour = <b>$form{colour}</b><br>\n&quot;;
print &quot;details = <b>$form{details}</b><br>\n&quot;;
print &quot;price = <b>$form{price}</b><br>\n&quot;;
print &quot;prefix = <b>$form{prefix}</b><br><br>\n&quot;;
print &quot;scriptaction = <b>$form{scriptaction}</b><br>\n&quot;;
print &quot;mainimage = <b>$form{mainimage}</b><br>\n&quot;;
print &quot;thumbimage = <b>$form{thumbimage}</b><br>\n&quot;;
print &quot;</body>\n&quot;;
print &quot;</html>&quot;;

Thanks for all your help with this. I'm in your debt.

Phil.
 
Right.

Have got the following to work (apologies for the huge post again). Its a cut down version of what you gave me mashed into the script I posted above.

Shouldn't be too much work to get it looking as it should.

hope it makes sense

Joe.

here we go :) :



#!/usr/bin/perl
use CGI;
$query = new CGI;


sub setFile {

print &quot;Content-type: text/html\n\n&quot;;
print &quot;<HTML>\n&quot;;
print &quot;<HEAD>\n&quot;;
print &quot;<SCRIPT language=\&quot;javascript\&quot;>\n&quot;;
print &quot; function CheckAndDo() {\n&quot;;
print &quot; // any confirmation / validation you need to do on the form here!\n&quot;;
print &quot; var v1=1;\n&quot;;
print &quot; }\n&quot;;
print &quot;</SCRIPT>\n&quot;;
print &quot;<TITLE>TRS Upload</TITLE>\n&quot;;
print &quot;</HEAD>\n&quot;;


print &quot;<FORM name=\&quot;Post_form\&quot; METHOD=\&quot;POST\&quot; ACTION=\&quot;####your var here####/upload_test.sh\&quot; ENCTYPE=\&quot;multipart/form-data\&quot; onSubmit=\&quot;return CheckAndDo()\&quot;>\n&quot;;
print &quot;<INPUT TYPE=\&quot;hidden\&quot; NAME=\&quot;DIR\&quot; VALUE=\&quot;/####your destination data directory here####\&quot;>\n&quot;;

print &quot;<TABLE cellspacing=\&quot;0\&quot;>\n&quot;;
print &quot;<TR>\n&quot;;
print &quot;<TD>Upload Files/TD>\n&quot;;
print &quot;</TR>\n&quot;;
print &quot;</TABLE>\n&quot;;
print &quot;<HR>\n&quot;;

print &quot;<TABLE cellspacing=\&quot;0\&quot;>\n&quot;;
print &quot;<TR>\n&quot;;
print &quot; <TD>File 1:</TD>\n&quot;;
print &quot; <TD><INPUT TYPE=\&quot;FILE\&quot; NAME=\&quot;FILE1\&quot; size=50 maxlength=80><INPUT TYPE=\&quot;hidden\&quot; NAME=\&quot;NEW1\&quot; VALUE=\&quot;new_file1\&quot;></TD>\n&quot;;
print &quot;</TR>\n&quot;;
print &quot;<TR>\n&quot;;
print &quot; <TD ID=\&quot;PHbody\&quot; class=\&quot;PHb\&quot;>File 2:</TD>\n&quot;;
print &quot; <TD><INPUT TYPE=\&quot;FILE\&quot; NAME=\&quot;FILE2\&quot; size=50 maxlength=80><INPUT TYPE=\&quot;hidden\&quot; NAME=\&quot;NEW2\&quot; VALUE=\&quot;new_file2\&quot;></TD>\n&quot;;
print &quot;</TR>\n&quot;;


print &quot;<TABLE cellspacing=\&quot;0\&quot;>\n&quot;;
print &quot;<TR>\n&quot;;
print &quot; <TD>HOLDING VARIABLES</TD>\n&quot;;
print &quot;</TR>\n&quot;;
print &quot;<TR>\n&quot;;
print &quot; <TD><INPUT TYPE=\&quot;text\&quot; NAME=\&quot;REFERENCE\&quot;></INPUT></TD>\n&quot;;
print &quot;</TR>\n&quot;;
print &quot;<TR>\n&quot;;
print &quot; <TD><INPUT TYPE=\&quot;text\&quot; NAME=\&quot;MAKE\&quot;></INPUT></TD>\n&quot;;
print &quot;</TR>\n&quot;;
print &quot;<TR>\n&quot;;
print &quot; <TD><INPUT TYPE=\&quot;text\&quot; NAME=\&quot;MODEL\&quot;></INPUT></TD>\n&quot;;
print &quot;</TR>\n&quot;;
print &quot;<TR>\n&quot;;
print &quot; <TD><INPUT TYPE=\&quot;text\&quot; NAME=\&quot;COLOUR\&quot;></INPUT></TD>\n&quot;;
print &quot;</TR>\n&quot;;
print &quot;<TR>\n&quot;;
print &quot; <TD><INPUT TYPE=\&quot;text\&quot; NAME=\&quot;PRICE\&quot;></INPUT></TD>\n&quot;;
print &quot;</TR>\n&quot;;
print &quot;</TABLE>\n&quot;;

print &quot;<TABLE cellspacing=\&quot;0\&quot;>\n&quot;;
print &quot;<TR>\n&quot;;
print &quot; <TD><INPUT TYPE=\&quot;submit\&quot; VALUE=\&quot;Upload\&quot;></INPUT></TD>\n&quot;;
print &quot;</TR>\n&quot;;
print &quot;</TABLE>\n&quot;;
print &quot;</FORM>\n&quot;;
print &quot;</BODY>\n&quot;;
print &quot;</HTML>\n&quot;;

}


sub addFile
{

## set the destination directory name
my $whatDir = $query->param('DIR');
$Data = &quot;$ENV{'DEVELOP'}/####your destination data directory path here####/$whatDir/&quot;;

## collect variables here, hardcoded for ease of reference
my $reference = $query->param('REFERENCE');
my $carmaker = $query->param('MAKE');
my $carmodel = $query->param('MODEL');
my $carcolor = $query->param('COLOUR');
my $carprice = $query->param('PRICE');

##### file upload scripting - do not alter as it should work #######

# Set all the other environment variables
@good_extensions = ('gif','jpg','JPG','jpeg','mpeg','bmp','txt','rpt','doc','png','csv','xls','pdf','html','htm','css','zip','tar.gz','xml','zip','ZIP','srg','SRG');
@bad_extensions = ('exe');
$max_size = 1000000;
$max_num_files = 10;

# Start the serious stuff from here
use CGI;
$max_num_files ||= 1;
$Data ||= $ENV{'DOCUMENT_ROOT'};
undef @bad_extensions if @good_extensions;
for(my $a = 1; $a <= $max_num_files; $a++) {
my $req = new CGI;
if($req->param(&quot;FILE$a&quot;)) {

# pick up new file name if requested
my $new = $req->param(&quot;NEW$a&quot;);
$new =~ s/ +/\_/g;
my $newname = $new;
$newname =~ s/^.*(\\|\/)//;

# pick up the file for download
my $file = $req->param(&quot;FILE$a&quot;);
#$file =~ s/ +/\_/g;
my $filename = $file;
$filename =~ s/^.*(\\|\/)//;

# get the new file extension
my $extension = $filename;
$extension =~ s/([^*]|\n)*\b\.//g;

# join the new file name with the reuired extension
my $wholename = join &quot;.&quot;,$newname,$extension;

# give the new string if new filename is defined
$filename = $wholename if $newname;
my $proceed_type = 0;

# validate the extension from the good extensions bit
if(@good_extensions) {
foreach(@good_extensions) {
my $ext = $_;
$ext =~ s/\.//g;
if($filename =~ /\.$ext$/) {
$proceed_type = 1;
last;
}
}
unless($proceed_type) {
push(@was_not_good_type, $filename);
}
}

# for bad extensions get names for later
elsif(@bad_extensions) {
$proceed_type = 1;
foreach(@bad_extensions) {
my $ext = $_;
$ext =~ s/\.//g;
if($filename =~ /\.$ext$/) {
$proceed_type = 0;
last;
}
}
unless($proceed_type) {
push(@was_a_bad_type, $filename);
}
} else {
$proceed_type = 1;
}

# either download or not and add names to arrays
if($proceed_type) {
if(open(OUTFILE, &quot;>$Data/$filename&quot;)) {
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);
push(@file_did_save, $filename);
} else {
push(@did_not_save, $filename);
}
}

# file too big error
if($max_size) {
if((-s &quot;$Data/$filename&quot;) > ($max_size * 1024)) {
push(@was_too_big, $filename);
unlink(&quot;$Data/$filename&quot;);
}
}
}
}

# the redirect bit
print &quot;Pragma: no-cache\n&quot;;
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<html>\n&quot;;
print &quot;<head>\n&quot;;
print &quot;<meta http-equiv=\&quot;Content-Type\&quot; content=\&quot;text/html; charset=iso-8859-1\&quot;>\n&quot;;
print &quot;<meta name=\&quot;Author\&quot; content=\&quot;Dotquake Web Services - info\@dotquake.com\&quot;>\n&quot;;
print &quot;<meta name=\&quot;Description\&quot; content=\&quot;MN Car Sales - Pre-owned cars from £300 upwards\&quot;>\n&quot;;
print &quot;<meta name=\&quot;Keywords\&quot; content=\&quot;car, sales, warranty, part exchange, bodywork repair, valet\&quot;>\n&quot;;
print &quot;<title>MN Car Sales</title>\n&quot;;
print &quot;</head>\n&quot;;

print &quot;<body bgcolor=\&quot;#F0F8FF\&quot;>\n&quot;;
print &quot;<table border=\&quot;0\&quot; cellpadding=\&quot;5\&quot; cellspacing=\&quot;0\&quot; width=\&quot;100%\&quot;>\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td valign=\&quot;top\&quot;>\n&quot;;
print &quot;<p><font face=\&quot;Verdana, Arial\&quot; size=\&quot;2\&quot;>The details for the new vehicle with reference number <b>$carreference ($carmaker $carmodel priced at $carprice)</b>, detailed below, have been successfully added and all relevant files have been uploaded and updated.</font></p>\n&quot;;
print &quot;<p><font face=\&quot;Verdana, Arial\&quot; size=\&quot;2\&quot;>Please click <a href=\&quot;admin_add.cgi\&quot; title=\&quot;Add another new vehicle\&quot;>here</a> to add another new vehicle, <a href=\&quot;admin_amend.cgi?method=POST&reference=$form{reference}\&quot; title=\&quot;Amend details for this vehicle\&quot;>here</a> to amend the details for this vehicle, or continue to navigate the site using the contents menu on the left of the screen.</font></p>\n&quot;;
print &quot;</td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;</table>\n&quot;;
print &quot;<table border=\&quot;0\&quot; cellpadding=\&quot;5\&quot; cellspacing=\&quot;0\&quot; width=\&quot;100%\&quot; >\n&quot;;
print &quot;<tr>\n&quot;;
print &quot;<td align=\&quot;right\&quot; nowrap><p><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot;><b>MN Car Sales, Proprietor: Mark Norton<br>St Andrews Yard, Willeys Avenue, Exeter, EX2 8EP<br>Enquiries: <a href=\&quot;mailto:enquiries\@mncarsales.co.uk\&quot; title=\&quot;Send email to MN Car Sales\&quot;>enquiries\@mncarsales.co.uk</a><br>Tel: 01392 276728, mobile: 07974 382416 (24 hr)</b></font></p></td>\n&quot;;
print &quot;</tr>\n&quot;;
print &quot;</table>\n&quot;;
print &quot;<p align=\&quot;right\&quot;><font face=\&quot;Verdana, Arial\&quot; size=\&quot;1\&quot; color=\&quot;#808080\&quot;><i>\n&quot;;
print &quot;<br>Best viewed at 800 x 600 pixels with browser version 4.0 or later<br>Design, programming & maintenance by <a href=\&quot; title=\&quot;Dotquake Web Services\&quot; target=\&quot;_blank\&quot;><img src=\&quot;../dwslogo.gif\&quot; border=\&quot;0\&quot; align=\&quot;absmiddle\&quot; width=\&quot;24\&quot; height=\&quot;14\&quot;></a> <a href=\&quot; title=\&quot;Dotquake Web Services\&quot; target=\&quot;_blank\&quot;>Dotquake Web Services</a></i></font></p>\n&quot;;
print &quot;</body>\n&quot;;
print &quot;</html>&quot;;
}



### just picks up on one of the params from the form - you could use an 'action' hidden field which'd make more sense

my $whatDir = $query->param('DIR');

if($whatDir) {
addFile
} else {
setFile
}
 
Cracked it!

I've learnt a big lesson here. I decided straight out that I didn't like the look of the CGI module so I decided to ignore it and do things the only way I knew how (after all, I'm still a relative novice when it comes to PERL). Now that I've looked at what it does and how it does it I realise how naive I've been!

Sincere thanks for all your help on this. It's good to know that there are decent people like you around who are willing to help others out just for the hell of it. I hope I didn't put you to too much trouble.

Phil.
 
glad to be of some help (its not often I can!) and ta for the star :)

I've been stuck in the past and this sites helped me no end so I'm just &quot;passing it on&quot;, as it were...

Joe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top