Hi everyone,

Thank you for reading my post.
I hope this is the right place where to post it.
Here is my problem.

I want to do some file uploading (sending files thanks to a "HTML" "FORM" 
with the "POST" method to a server).

I use a c-cgi script to get the data (the file characters).

Here is my code:

================================================================
int main()
{
int content_length;
char * s_content;
int i;
int c;

  printf("Content-type: text/html\n\n") ;
  printf("<HTML>\n") ;
  printf("<HEAD>\n") ;
  printf("<TITLE>Uploading result</TITLE>\n") ;
  printf("</HEAD>\n") ;
  printf("<BODY>\n") ;
  printf("<H1>Uploading result</H1>\n") ;

  content_length = atoi(getenv("CONTENT_LENGTH"));
  if(content_length == 0)
    return 0;

  printf("<BR>content_length: %d", content_length);
  printf("<BR>");       

  s_content = (char *) malloc(sizeof(char) * content_length);
  if(s_content == NULL)
    return 0;

  i = 0;
  c = getchar();
  while(c != EOF)
  {
    s_content[i] = c;
    c = getchar();
    i++;
  }

  printf("<BR>At the end i = %d", i);

  free(s_content);

  return 1;
}
================================================================

When I try to upload a "jpg" file, I get the following output
(the size of the file is 32 KB):

========================
Uploading result
content_length: 32468
At the end i = 1442
========================

As you can see, the value of the environment variable "CONTENT_LENGTH"
differs from the value of the variable "i" at the end of the loop.

Can you please help me find where the problem is coming from?

Thanks in advance for your help.

--
Léa Massiot
-- 
View this message in context: 
http://www.nabble.com/c-cgi-script---html-file-uploading-tp19780000p19780000.html
Sent from the C-prog mailing list archive at Nabble.com.

Reply via email to