data.txt
- Kod: Označi sve
tekst koj treba da se iscita
drugi red teksta
treci red teksta
data.c
- Kod: Označi sve
#include <stdio.h>
#include <stdlib.h>
#define DATAFILE "../data/data.txt"
int main(void)
{
FILE *f = fopen(DATAFILE,"r");
int ch;
if(f == NULL) {
printf("%s%c%c\n",
"Content-Type:text/html;charset=utf-8",13,10);
printf("<title>nezgodno</title>\n");
printf("<p><em>nisam u mogucnosti da otvorim data fajl, sorry!</em></p>"); }
else {
printf("%s%c%c\n",
"Content-Type:text/plain;charset=utf-8",13,10);
while((ch=getc(f)) != EOF)
putchar(ch);
fclose(f); }
return 0;
}
A sad ga iskompajlirajmo:
- Kod: Označi sve
gcc data.c -o data.cgi
data.c je vas izvorni kod i nije vam potreban jer posle kompajliranja ostaje izvrsni program data.cgi
Promenimo dozvole u izvrsne i promenimo ownership:
- Kod: Označi sve
chmod a+x /var/www/cgi-bin/data.cgi
chown -R www-data:www-data /var/www/cgi-bin/data.cgi
Na lokaciji:
http://localhost/cgi-bin/data.cgi
se treba iscitati sadrzaj data.txt fajla !!!