将txt文件内容通过cgi和apache显示在网页上
生活随笔
收集整理的這篇文章主要介紹了
将txt文件内容通过cgi和apache显示在网页上
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
準備工作:
參考博客:在linux上實現cgi內容在網頁上顯示
一、c語言cgi程序和data.txt
data.txt
aaaaa將txt文件和c文件都存放于/var/www/cgi-bin文件夾下
test01.c
#include <stdio.h> #include <stdlib.h> //#define TEST_FILE "C:\Users\taw19960426\Desktop\data.txt"int main(void) {FILE *fp;//fp=fopen(TEST_FILE,"r");char ch;//char a[45];if((fp=fopen("./data.txt","r"))==NULL){printf("Content-Type: text/html;charset=utf-8\r\n\r\n");printf("無法打開文件");}else{printf("Content-Type: text/html;charset=utf-8\r\n\r\n");//printf("%s%c%c","Content-Type: text/plain",13,10);while((ch=getc(fp))!=EOF)putchar(ch);fclose(fp);}return 0; }二、開啟apache和cgi文件的產生
1.apache的開啟
[root@VM_0_13_centos ~]# systemctl start httpd [root@VM_0_13_centos ~]# service httpd status2.cgi文件的生成
[root@VM_0_13_centos cgi-bin]# tcc test01.c -o test01.cgi三、結果顯示
httpd默認訪問端口是80
接下來在網頁中輸入網址:http://IP/cgi-bin/test01.cgi(即http://ip:端口號/CGI文件名) 訪問結果如圖:
總結
以上是生活随笔為你收集整理的将txt文件内容通过cgi和apache显示在网页上的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在linux上实现cgi内容在网页上显示
- 下一篇: Vim学习及实践