How to get HTML selected value and process in C? -


i got code in c shows list of directories in specific path , need show these directories in html select:

/*  * listdir.c - leer archivo de un directorio  */ #include <stdio.h> #include <stdlib.h> #include <dirent.h>  void err_quit(char *msg);  int main(int argc, char *argv[]) {     dir *dir;     struct dirent *mydirent;     int = 1;      if(argc != 2) {     //puts("uso: listdir {pathname}");     //exit(exit_failure);     argv[1]="/home/maudev";     }      if((dir = opendir(argv[1])) == null)     {     err_quit("opendir");     }     printf("%s%c%c\n","content-type:text/html;charset=iso-8859-1",13,10);     printf("<title>carpetas</title>\n");     printf("<h3>carpetas</h3>\n");     printf("<select>\n");     while((mydirent = readdir(dir)) != null)     {           printf("\n<option value='%s'>%s",mydirent->d_name,mydirent->d_name);          printf("</option>\n");     }     printf("</select>\n");     closedir(dir);     exit(exit_success); }  void err_quit(char *msg) {     perror(msg);     exit(exit_failure); } 

this code, default im showing list of directories /home/maudev/, shows list of directories perfectly, need select 1 of these folders , show again folders contains, , don't know how that, please me.

in html part, add form , submit (via post method) selected value:

printf("<form action=\"app.cgi\" method=\"post\">\n"); printf("<select>\n"); while((mydirent = readdir(dir)) != null) {       printf("<option value=\"%s\">%s</option>\n", mydirent->d_name, mydirent->d_name);  } printf("</select>\n"); printf("<input type=\"submit\">\n"); printf("</form>\n"); 

in c part, read stdin , use post-data value:

len_ = getenv("content_length"); len = strtol(len_, null, 10); postdata = malloc(len + 1); if (!postdata) {exit(exit_failure);} fgets(postdata, len + 1, stdin); /* work postdata */ free(postdata); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -