博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

白石电子工作室

Keep It Simple and Stupid!
   whitestone.cublog.cn
关于作者  
姓名:jpzhou
职业:嵌入式开发工程师
年龄:30
位置:
个性介绍:龙马精神

我的分类  




CGI中文件无法上传

CGI中文件无法上传

    在调试cgictest.cgi过程中,发现文件无法上传,提示“No file was uploaded.”。

    原因有两点:

    1、boa的用户权限不够,无法建立临时文件。改为root用户启动

    2、cgi是以GET形式发送表格的。改为POST形式。

 发表于: 2007-03-29,修改于: 2007-03-29 11:01 已浏览591次,有评论2条 推荐 投诉

  网友评论
  本站网友 时间:2007-11-17 15:21:10 IP地址:218.104.96.★
您好,您是使用CGIC库写的程序上传文件吗?
可不可以不使用CGIC实现文件的上传和下载呢?

Blog作者的回复:
不用CGIC,你有更好的方法么?我很想知道。

  本站网友 时间:2008-07-04 09:05:20 IP地址:116.225.170.★
请问如何实现文件下载到目标板上呢?

Blog作者的回复:
int download_file( int type )
{
    cgiFilePtr file;
    char name[1024];
    char *pFileName;
    char filename[128];
    char *pStr;
    char contentType[1024];
    char buffer[1024];
    int size;
    int got;
    FILE *fp;

    if(cgiFormFileName(pDownloadFile[type], name, sizeof(name)) != cgiFormSuccess)
    {
        printf("<p>No file was downloaded.<p>\n");
        flag_success[type]=-1;
        return -1;
    }
    pFileName = name;
    while(1)
    {
        if((pStr = strstr(pFileName,"\\"))==NULL)
        {
            break;
        }
        pFileName = pStr + 1;
    }
    //fprintf(cgiOut, "The filename submitted was: ");
    //cgiHtmlEscape(pFileName);
    //fprintf(cgiOut, "<p>\n");
    cgiFormFileSize(pDownloadFile[type], &size);
    //fprintf(cgiOut, "The file size was: %d bytes<p>\n", size);
    cgiFormFileContentType(pDownloadFile[type], contentType, sizeof(contentType));
    //fprintf(cgiOut, "The alleged content type of the file was: ");
    //cgiHtmlEscape(contentType);
    //fprintf(cgiOut, "<p>\n");
    //fprintf(cgiOut, "Of course, this is only the claim the browser made when downloading the file. Much like the filename, it cannot be trusted.<p>\n");
    //fprintf(cgiOut, "The file's contents are shown here:<p>\n");
    if (cgiFormFileOpen(pDownloadFile[type], &file) != cgiFormSuccess)
    {
        fprintf(cgiOut, "Could not open the file.<p>\n");
        flag_success[type]=-1;
        return -1;
    }
    //fprintf(cgiOut, "<pre>\n");

    sprintf(filename,"%s%s",pTargetFile[type],pFileName);
    if((fp = fopen(filename,"w+"))<0)
    {
        fprintf(cgiOut,"CGI无法打开该目标文件<BR>\n");
    }
    while (cgiFormFileRead(file, buffer, sizeof(buffer), &got) == cgiFormSuccess)
    {
    //    cgiHtmlEscapeData(buffer, got);

        fwrite(buffer,sizeof(char),got,fp);
    }
    fclose(fp);
    //fprintf(cgiOut, "</pre>\n");
    cgiFormFileClose(file);

    flag_success[type]=1;

    return 0;
}


  发表评论



Copyright © 2001-2006 ChinaUnix.net All Rights Reserved

感谢所有关心和支持过ChinaUnix的朋友们
页面生成时间:0.15774

京ICP证041476号