🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #1019

Re: CGI how to write program for accepting file uploaded to server

#1019
From: zhangsn
Date: Tue, 25 Oct 2005 14:18
78 lines
3192 bytes
#include "stdafx.h"
#include <stdlib.h>
int main()
{
int i,n;
printf ("Contenttype:text/plain\n\n");
n=0;
printf ("Content-Length");
if(getenv("Content-Length"))
n=atoi(getenv("Content-Length"));
printf ("%d",n);
for (i=0;i<n;i++)
putchar(getchar());
putchar ('\n');
fflush(stdout);
}

output :Content-Length0
WHY??????????????

My html code:
<html>

<head>
<title>ghghfd</title>
</head>

<body>

<form method="POST" action="http:\\localhost\yu\cgi1.exe">

  <table border="1" width="100%">
    <tr>
      <td width="50%"><input type="submit" value="ok" name="B1"> <input
type="text" name="T1" size="20"></td>
      <td width="50%">ghghfd&nbsp;&nbsp;&nbsp; <input type="text" name="T2"
size="20"></td>
    </tr>
    <tr>
      <td width="50%">?</td>
      <td width="50%"><select size="1" name="D1">
          <option selected>d1</option>
          <option>d2</option>
          <option>d3</option>
        </select></td>
    </tr>
  </table>
</form>
</body>

</html>


"Hans Galema" <notused@notused.nl> ??????:435b9697@newsgroups.borland.com...
> zhangsn wrote:
>
> > I do not start to write code. because it is my touch on CGI at the
fourth
> > day.
>
> You better start writing code and do some testing.
>
> First make a .txt file (notepad) with a known content. Then upload it.
> Your cgi-exe can read CONTENT_LENGTH bytes from stdin. Write all
> to a file. Then examine the file. You will find the content
> of the original file back and something added in front and after.
> Then you will know how to handle Content -Type: text/plain.
>
> After having done so you could try with a known .html file.
> What kind of files should the browser upload ?
>
> Well all may be specified in a RFC. But I did find it out as described
> for some types. Incredibly the formatting/coding is different for
> nearly all different filetypes. But who will you blame ?
>
> Hans.
>
> Please trim quotes.
Technical Details
Message-ID: <435e3d3b$3@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <435a2142@newsgroups.borland.com> <435a3d89@newsgroups.borland.com> <435a4548$1@newsgroups.borland.com> <435ad565@newsgroups.borland.com> <435b67d8$1@newsgroups.borland.com> <435b780e@newsgroups.borland.com> <435b9697@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,943780c8a609b3ea
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "zhangsn" <zhangsn98@sohu.com>
From: "zhangsn" <zhangsn98@sohu.com>
Newsgroups: borland.public.cppbuilder.internet.web
References: <435a2142@newsgroups.borland.com> <435a3d89@newsgroups.borland.com> <435a4548$1@newsgroups.borland.com> <435ad565@newsgroups.borland.com> <435b67d8$1@newsgroups.borland.com> <435b780e@newsgroups.borland.com> <435b9697@newsgroups.borland.com>
Subject: Re: CGI how to write program for accepting  file uploaded to server
Date: Tue, 25 Oct 2005 22:18:38 +0800
Lines: 80
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 219.149.28.53
Message-ID: <435e3d3b$3@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1130249531 219.149.28.53 (25 Oct 2005 07:12:11 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail