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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flat File database 1

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
US
I have a cgi script that simply puts all values for each key into a flat file database.

Mindy|a|Ferguson|||0||on black|photo|Headshot||Mindy|0|||Ferguson|2001|Mindy|Upload|


However if you set the <form enctype=&quot;multipart/form-data&quot;> in the html file, the flatfile database looks like this:

&quot;Caption&quot;



Mindy

-----------------------------7d1b92a16009c

Content-Disposition: form-data; name|

I need the file to look like the first example but I need to set the enctype so I can upload a jpeg file.

Any ideas?

Thanks

Mindy
 
the crystal ball is a little foggy still.;-).... can you give a little more detail? Maybe post a small section of code that is representative of what you are using...??




keep the rudder amid ship and beware the odd typo
 
Here is the entire code.....

#!/usr/local/bin/perl5


if ($ENV{'REQUEST_METHOD'} eq 'GET')
{
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else
{
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<P>Use POST or GET</P>&quot;;
}

foreach $pair (@pairs)
{
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack(&quot;C&quot;,hex($1)) /eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9] [a-fA-F0=9])/pack(&quot;C&quot;, hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
#$FORM{'name'} = $value;

if ($formdata{$key})
{
$formdata{$key} .= &quot;, $value&quot;;
}
else
{
$formdata{$key} = $value;
}
}
print &quot;Content-type: text/html\n\n&quot;;
open(GB, &quot;>>APGB.txt&quot;);

foreach $key (sort keys(%formdata))
{
print GB &quot;$formdata{$key}|&quot;;
}
print GB &quot;\n&quot;;
print &quot;<html><head><title>Associated Press - Graphics Bank</title></head>&quot;;
print &quot;<body>&quot;;
print &quot;<P>The information has been saved to a log.</P>&quot;;
print &quot;<P>The file has been uploaded.</P>&quot;;
print &quot;</BODY></HTML>&quot;;
close(GB);
 
no rocket science there.. pretty normal stuff.... What does the HTML input page look like?


keep the rudder amid ship and beware the odd typo
 

<!-- Associated Press - Broadcast News Services -->
<!-- Copyright (c) 2001 Associated Press -->
<!-- Written by Mindy Ferguson -->

<HTML>
<HEAD>
<META HTTP-EQUIV=Set-Cookie CONTENT=&quot;ApCookie=x%07S%13s%B3%EC%E1%E5%25%11x%F6%F2%04VF%D3%1D01%B1%15Wk%E4%86%17%2Aa%B2%DB%D7%E8JJ%F3%AB%C3_%83%E3%E3el%29a%A3%3A%5C0%87%AA%E8%28%DD%81%E7%9A%90%E2%C0%3Fd%E5D%06%AB%9D%25%27%DFH%EE%CE%B2s%C7n%E5%AC%9D%AC+%93%8C%FD%3E%89%27B4%95%C4R%0D%D6%98G%10%89%E1l%1FI%FF%EC%1E%AD%EC%AD%8F%D3%F2%82%1D%83C%FA%24wsF%9D%DC%A3%95%5C%5CKd%08i%05%AA%C8%D7Dy%8A%7E%D4%B9%B2%03g1%84%27%80%A1Q%8D%AF%A6%F4%21%83%8E%8E4%87%0A%FC%21%0Fn%EC5%C2%DC%C9v%3Dm%A0%D6G%5D%FF%0BCN%9F%3A%A1%D4%A0%CA.n%5C%5C%7Cdf%0E%C0%EEP%C7%7F%CE%05%0E%85q%EF%B7J%9D%5B%3D%8D%C6%C0%3Ah%BC%D0I%BE%06%F7%2C%86%10%98%93%18%BA%F0%CA%98%E0+%1C%E8%E1n%B6%C8%CD%DBUI8%17W%A6s1%E8%F8p%AD%A9%DB%E5%99z%F9%23%9CA%9B%EEk%A3%3F%EA%A29%F2x03u%8B%AF%BE%CC%7DD; path=/;&quot;>
<META HTTP-EQUIV=Set-Cookie CONTENT=&quot;ApSettings=x; path=/; expires=Friday, 31-Dec-2030 00:00:00 GMT&quot;>
<TITLE>Upload New Image</TITLE>
</HEAD>
<BODY BGCOLOR=black TEXT=white LINK=&quot;#F6FF45&quot; ALINK=&quot;#DAE0FF&quot; VLINK=&quot;#08FF2E&quot;>
<H2>Upload New Image</H2>
<P>
<FORM ACTION=&quot;cgi/upload.cgi&quot; METHOD=&quot;post&quot;>
<TABLE BORDER=0 WIDTH=&quot;100%&quot;>
<TR>
<TD ALIGN=right> Caption: </TD>
<TD ALIGN=left COLSPAN=2>
<TEXTAREA NAME=Caption ROWS=3 COLS=60 WRAP=virtual></TEXTAREA>
</TD>
</TR>
<TR>
<TD ALIGN=right> Image&nbsp;Type: </TD>
<TD ALIGN=left COLSPAN=2>
<SELECT NAME=Image_Type><OPTION VALUE=&quot;Headshot&quot;>--- Type ---
<OPTION VALUE=&quot;Headshot&quot;>Headshot
<OPTION VALUE=&quot;Cutout Headshot&quot;>Cutout Headshot
<OPTION VALUE=&quot;Logo&quot;>Logo
<OPTION VALUE=&quot;Map&quot;>Map
<OPTION VALUE=&quot;Drawing&quot;>Drawing
<OPTION VALUE=&quot;Flag&quot;>Flag
</SELECT>
<SELECT NAME=Image_Format><OPTION VALUE=&quot;&quot;>--- Format ---
<OPTION VALUE=&quot;photo&quot;>photo
<OPTION VALUE=&quot;graphic element&quot;>graphic element
<OPTION VALUE=&quot;partial graphic&quot;>partial graphic
<OPTION VALUE=&quot;finished graphic&quot;>finished graphic
<OPTION VALUE=&quot;video still&quot;>video still
</SELECT>
<SELECT NAME=Image_Background><OPTION VALUE=&quot;&quot;>--- Background ---
<OPTION VALUE=&quot;on black&quot;>on black
<OPTION VALUE=&quot;on white&quot;>on white
<OPTION VALUE=&quot;on gray&quot;>on gray
</SELECT>
</TD>
</TR>
<TR>
<TD ALIGN=right> Category: </TD>
<TD ALIGN=left COLSPAN=2>
<PRE><SELECT NAME=Category>
<OPTION VALUE=&quot;&quot; SELECTED>--- Category ---
<OPTION VALUE=&quot;a&quot;>General&nbsp;Domestic&nbsp;News
<OPTION VALUE=&quot;b&quot;>Special&nbsp;Events
<OPTION VALUE=&quot;c&quot;>Features
<OPTION VALUE=&quot;cA&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Stocking&nbsp;Stuffers
<OPTION VALUE=&quot;ca&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Flashback
<OPTION VALUE=&quot;cb&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Between&nbsp;the&nbsp;Lines
<OPTION VALUE=&quot;cc&quot;>&nbsp;&nbsp;&nbsp;&nbsp;ConsumerWatch
<OPTION VALUE=&quot;cd&quot;>&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;Other&nbsp;News
<OPTION VALUE=&quot;ce&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Home&nbsp;Entertainment&nbsp;Update
<OPTION VALUE=&quot;cf&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Film&nbsp;Clips
<OPTION VALUE=&quot;cg&quot;>&nbsp;&nbsp;&nbsp;&nbsp;General&nbsp;Entertainment
<OPTION VALUE=&quot;ch&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Health&nbsp;and&nbsp;Medicine
<OPTION VALUE=&quot;ci&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Eye&nbsp;On&nbsp;TV
<OPTION VALUE=&quot;cj&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Country&nbsp;Music&nbsp;Report
<OPTION VALUE=&quot;ck&quot;>&nbsp;&nbsp;&nbsp;&nbsp;On&nbsp;the&nbsp;Homefront
<OPTION VALUE=&quot;cl&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Consuming&nbsp;Interest
<OPTION VALUE=&quot;cm&quot;>&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;Music&nbsp;Report
<OPTION VALUE=&quot;cn&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Country
<OPTION VALUE=&quot;co&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Rock
<OPTION VALUE=&quot;cp&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Grammy&nbsp;Preview
<OPTION VALUE=&quot;cq&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Chip&nbsp;Talk
<OPTION VALUE=&quot;cr&quot;>&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;Hollywood&nbsp;Report
<OPTION VALUE=&quot;cs&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Segue
<OPTION VALUE=&quot;ct&quot;>&nbsp;&nbsp;&nbsp;&nbsp;TravelMinute
<OPTION VALUE=&quot;cu&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Urban
<OPTION VALUE=&quot;cv&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Oscar&nbsp;Preview
<OPTION VALUE=&quot;cw&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Newsweek&nbsp;Perspective
<OPTION VALUE=&quot;cx&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Tax&nbsp;Break
<OPTION VALUE=&quot;cy&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Yearenders
<OPTION VALUE=&quot;cz&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Today&nbsp;in&nbsp;Entertainment&nbsp;History
<OPTION VALUE=&quot;d&quot;>National&nbsp;News&nbsp;Agenda
<OPTION VALUE=&quot;e&quot;>Entertainment
<OPTION VALUE=&quot;eg&quot;>&nbsp;&nbsp;&nbsp;&nbsp;General
<OPTION VALUE=&quot;en&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Country
<OPTION VALUE=&quot;eo&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Rock
<OPTION VALUE=&quot;eu&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Urban
<OPTION VALUE=&quot;f&quot;>Financial/Business
<OPTION VALUE=&quot;g&quot;>State&nbsp;News&nbsp;Agenda
<OPTION VALUE=&quot;h&quot;>National&nbsp;NewsMinute
<OPTION VALUE=&quot;i&quot;>International&nbsp;News
<OPTION VALUE=&quot;j&quot;>State&nbsp;NewsMinute
<OPTION VALUE=&quot;jl&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Lottery
<OPTION VALUE=&quot;jn&quot;>&nbsp;&nbsp;&nbsp;&nbsp;News
<OPTION VALUE=&quot;k&quot;>Commentary
<OPTION VALUE=&quot;l&quot;>Lifestyle
<OPTION VALUE=&quot;m&quot;>Agriculture
<OPTION VALUE=&quot;n&quot;>General&nbsp;State&nbsp;News
<OPTION VALUE=&quot;o&quot;>Weather
<OPTION VALUE=&quot;p&quot;>Political&nbsp;News
<OPTION VALUE=&quot;q&quot;>Sports&nbsp;Scores
<OPTION VALUE=&quot;qb&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Baseball
<OPTION VALUE=&quot;qe&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Soccer
<OPTION VALUE=&quot;qf&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Football
<OPTION VALUE=&quot;qg&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Golf
<OPTION VALUE=&quot;qh&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Hockey
<OPTION VALUE=&quot;qi&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Track&nbsp;and&nbsp;Field
<OPTION VALUE=&quot;qk&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Basketball
<OPTION VALUE=&quot;qm&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Motor&nbsp;Sports
<OPTION VALUE=&quot;qn&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Swimming
<OPTION VALUE=&quot;qo&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Olympics
<OPTION VALUE=&quot;qt&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Tennis
<OPTION VALUE=&quot;qx&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Boxing
<OPTION VALUE=&quot;r&quot;>Radio&nbsp;Advisories
<OPTION VALUE=&quot;s&quot;>Sports&nbsp;Stories
<OPTION VALUE=&quot;sb&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Baseball
<OPTION VALUE=&quot;se&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Soccer
<OPTION VALUE=&quot;sf&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Football
<OPTION VALUE=&quot;sg&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Golf
<OPTION VALUE=&quot;sh&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Hockey
<OPTION VALUE=&quot;si&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Track&nbsp;and&nbsp;Field
<OPTION VALUE=&quot;sk&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Basketball
<OPTION VALUE=&quot;sm&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Motor&nbsp;Sports
<OPTION VALUE=&quot;sn&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Swimming
<OPTION VALUE=&quot;so&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Olympics
<OPTION VALUE=&quot;st&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Tennis
<OPTION VALUE=&quot;sx&quot;>&nbsp;&nbsp;&nbsp;&nbsp;Boxing
<OPTION VALUE=&quot;t&quot;>Television&nbsp;Advisories
<OPTION VALUE=&quot;v&quot;>General&nbsp;Advisories
<OPTION VALUE=&quot;w&quot;>Washington&nbsp;News
</SELECT></PRE>
</TD>
</TR>
<TR>
<TD ALIGN=right> Keywords: </TD>
<TD ALIGN=left COLSPAN=2>
<INPUT NAME=Keywords VALUE=&quot;&quot; SIZE=60>
</TD>
</TR>
<TR>
<TD ALIGN=right> Source: </TD>
<TD ALIGN=left COLSPAN=2>
<INPUT NAME=Source VALUE=&quot;&quot; SIZE=60>
</TD>
</TR>
<TR>
<TD ALIGN=right> Copyright: </TD>
<TD ALIGN=left COLSPAN=2>
<INPUT NAME=Copyright VALUE=&quot;&quot; SIZE=60>
</TD>
</TR>
<TR>
<TD ALIGN=right> Permission&nbsp;From: </TD>
<TD ALIGN=left COLSPAN=2>
<INPUT NAME=Permission VALUE=&quot;&quot; SIZE=60>
</TD>
</TR>
<TR>
<TD ALIGN=right> Restrictions: </TD>
<TD ALIGN=left COLSPAN=2>
<INPUT NAME=Restrictions VALUE=&quot;&quot; SIZE=60>
</TD>
</TR>
<TR>
<TD ALIGN=right> Initials: </TD>
<TD ALIGN=left> <INPUT NAME=Initials VALUE=&quot;&quot; SIZE=11> </TD>
<TD ALIGN=center ROWSPAN=5>
</TD>
</TR>
<TR>
<TD ALIGN=right NOWRAP>Date Created: </TD>
<TD ALIGN=left>
<INPUT NAME=Date_Created SIZE=11 MAXLENGTH=10 VALUE=&quot;&quot;>
(YYYY/MM/DD)
</TD>
</TR>
<TR>
<TD ALIGN=right NOWRAP>Date Edited: </TD>
<TD ALIGN=left>
<INPUT NAME=Date_Edited SIZE=11 MAXLENGTH=10 VALUE=&quot;&quot;>
(YYYY/MM/DD)
</TD>
</TR>
<TR>
<TD ALIGN=right> Id: </TD>
<TD ALIGN=left>
<INPUT NAME=ID: SIZE=11 MAXLENGTH=10 VALUE=&quot;&quot;>
</TD>
</TR>
<TR>
<TD ALIGN=right>
New&nbsp;image:
</TD>
<TD ALIGN=left COLSPAN=2>
<INPUT TYPE=&quot;file&quot; NAME=&quot;New_Image&quot; ACCEPT=&quot;image/jpeg&quot; SIZE=&quot;40&quot;>
</TD>
</TR>
<TR>
<TD ALIGN=right> New&nbsp;matte: </TD>
<TD ALIGN=left COLSPAN=2>
<INPUT TYPE=&quot;file&quot; NAME=&quot;New_Matte&quot; ACCEPT=&quot;image/jpeg&quot; SIZE=&quot;40&quot;>
</TD>
</TR>
<TR>
<TD ALIGN=right>
Linked Id:
</TD>
<TD ALIGN=left>
<INPUT NAME=Link_ID SIZE=11 MAXLENGTH=6 VALUE=&quot;0&quot;>
(Leave 0 if both New Image and New Matte given)
</TD>
</TR>
<TR>
<TD>
<INPUT TYPE=hidden NAME=Free VALUE=&quot;0&quot;><INPUT TYPE=submit NAME=what VALUE=&quot;Upload&quot;>
</TD>
<TD COLSPAN=2>
<INPUT TYPE=reset VALUE=&quot;Reset Form&quot;>
</TD>
</TR>
</TABLE>
</FORM>
<P><HR>
<FORM>
<INPUT TYPE=button VALUE=&quot;Back to results page&quot; ONCLICK=&quot;history.go(-1)&quot;>
</FORM>
</BODY>
</HTML>
 
If anyone is interested, I was able to fix all problems by using the CGI.pm as listed below.

#!/usr/local/bin/perl5

use CGI;

$query = CGI::new();
$caption = $query->param(&quot;Caption&quot;);
$type = $query->param(&quot;Image_Type&quot;);
$format = $query->param(&quot;Image_Format&quot;);
$background = $query->param(&quot;Image_Background&quot;);
$category = $query->param(&quot;Category&quot;);
$keywords = $query->param(&quot;Keywords&quot;);
$source = $query->param(&quot;Source&quot;);
$copyright = $query->param(&quot;Copyright&quot;);
$permission = $query->param(&quot;Permission&quot;);
$restrictions = $query->param(&quot;Restrictions&quot;);
$initials = $query->param(&quot;Initials&quot;);
$createdate = $query->param(&quot;Date_Created&quot;);
$editdate = $query->param(&quot;Date_Edited&quot;);
$id = $query->param(&quot;ID:&quot;);
$newimage = $query->param(&quot;New_Image&quot;);
$newmatte = $query->param(&quot;New_Matte&quot;);
$link = $query->param(&quot;Link_ID&quot;);
open (GB, &quot;>>APGB.txt&quot;);
print GB &quot;$caption|$type|&quot;;
print GB &quot;$format|$background|&quot;;
print GB &quot;$category|$keywords|&quot;;
print GB &quot;$source|$copyright|&quot;;
print GB &quot;$permission|$restrictions|&quot;;
print GB &quot;$initials|$createdate|&quot;;
print GB &quot;$editdate|$id|&quot;;
print GB &quot;$newimage|$newmatte|$link\n&quot;;
close(GB);
 
Cool! Sorry I was not of more assistance. 'Glad you got it figured out. :)


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top