免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5490 | 回复: 8
打印 上一主题 下一主题

linux cgi怎么写文件? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-19 14:24 |只看该作者 |倒序浏览
我fopen一个文件,可以读取里面的文件内容,但是不能往文件里写入内容?
请问怎么写内容?

论坛徽章:
11
技术图书徽章
日期:2014-03-01 14:44:34天蝎座
日期:2014-05-21 22:11:59金牛座
日期:2014-05-30 17:06:14
2 [报告]
发表于 2012-03-19 15:33 |只看该作者
看你的需求,应该用 fopen(..., "r+")


    ``r''   Open text file for reading.  The stream is positioned at the beginning of the file.

     ``r+''  Open for reading and writing.  The stream is positioned at the beginning of the file.

     ``w''   Truncate to zero length or create text file for writing.  The stream is positioned at the beginning of the file.

     ``w+''  Open for reading and writing.  The file is created if it does not exist, otherwise it is truncated.  The stream is positioned at
             the beginning of the file.

     ``a''   Open for writing.  The file is created if it does not exist.  The stream is positioned at the end of the file.  Subsequent writes
             to the file will always end up at the then current end of file, irrespective of any intervening fseek(3) or similar.

     ``a+''  Open for reading and writing.  The file is created if it does not exist.  The stream is positioned at the end of the file.  Sub-
             sequent writes to the file will always end up at the then current end of file, irrespective of any intervening fseek(3) or simi-
             lar.

论坛徽章:
0
3 [报告]
发表于 2012-03-19 15:55 |只看该作者
timespace 发表于 2012-03-19 15:33
看你的需求,应该用 fopen(..., "r+")


这个我知道。
我的问题牵涉到cgi的用户权限问题
比如他的配置:
#chroot
user=root#default = nobody

LS,你尝试下写一个CGI程序,提交的表单是"POST",目的是往本地flash文件中写入数据,就清楚我的问题的关键了,可能你还没遇到过这种问题吧

论坛徽章:
11
技术图书徽章
日期:2014-03-01 14:44:34天蝎座
日期:2014-05-21 22:11:59金牛座
日期:2014-05-30 17:06:14
4 [报告]
发表于 2012-03-19 17:55 |只看该作者
你开始问题的描述就不清楚,只能让人误解了
和什么CGI,什么POST表单没直接联系,就是用户权限的问题
比如CGI进程以nobody运行,nobody对flash文件没有写权限,当然操作不会成功了

解决办法很多,选自己能做到且被允许的操作:
改flash文件权限,使nobody可写;
有文件上传,一定要有对应权限的目录,否则就是自讨没趣;
CGI调用web服务器本地的某个程序,该程序有权限写flash文件;
CGI不在web服务器本地保存文件,发送到某个你有更多权限的机器;



论坛徽章:
0
5 [报告]
发表于 2012-03-20 02:48 |只看该作者
:wink::wink::wink::wink::wink::wink:

论坛徽章:
0
6 [报告]
发表于 2012-03-20 14:45 |只看该作者
timespace 发表于 2012-03-19 17:55
你开始问题的描述就不清楚,只能让人误解了
和什么CGI,什么POST表单没直接联系,就是用户权限的问题
比如 ...


多谢!

论坛徽章:
0
7 [报告]
发表于 2012-03-20 15:45 |只看该作者
[quote]timespace 发表于 2012-03-19 17:55
改flash文件权限,使nobody可写;
quote]

怎么修改文件权限,使nobody可写?我chmod 777 该文件夹,都不行啊

论坛徽章:
0
8 [报告]
发表于 2012-04-25 11:40 |只看该作者
顶一个,我也是,cgi写别的分区文件,不行,chmod 777 文件夹和文件ms还不行?晕啊,最后我修改本文件夹的,然后cp到别的文件夹。下午再试试

论坛徽章:
0
9 [报告]
发表于 2012-04-25 20:01 |只看该作者
将放在/cgi-bin下面的文件增加权限 chmod +s 文件名
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP