怎么样让PHP在WINDOWS下读盘

lingdang 2000-03-15 02:32:00
为什么我的这个程序通不过
运行时会出现DOS窗口
<html>
<head>
<title>访客计数器 原型</title>
</head>
<body>
<?php
/*
simple access counter for php3
(c)1998 David W. Bettis
dbettis@eyeintegrated.com
medify by Wilson Peng
*/

$counterFile = "/tmp/counter.txt";

function displayCounter($counterFile) {
$fp = fopen($counterFile,"rw");
$num = fgets($fp,5);
$num += 1;
print "您是第 "."$num"." 位无聊份子";
exec( "rm -rf $counterFile");
exec( "echo $num > $counterFile");
}

if (!file_exists($counterFile)) {
exec( "echo 0 > $counterFile");
}

displayCounter($counterFile);

?>
</body>
</html>

...全文
232 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
limodou 2000-04-20
  • 打赏
  • 举报
回复
<html>
<head>
<title>访客计数器 原型</title>
</head>
<body>
<?php
/*
simple access counter for php3
(c)1998 David W. Bettis
dbettis@eyeintegrated.com
medify by Wilson Peng
*/

//!!!!!!!!!!!改成一个存在的目录
//$counterFile = "/tmp/counter.txt";
$counterFile="counter.txt";

function displayCounter($counterFile) {

if (!file_exists($counterFile)) {
$num=1;
}
else
{
//!!!!!!!!不要又读又写 $fp = fopen($counterFile,"rw");
$fp=fopen($counterFile, "r");
$num = fgets($fp,5);
$num += 1;
//将写入分开
fclose($fp);
}
print "您是第 "."$num"." 位无聊份子";
// exec( "rm -rf $counterFile");
// exec( "echo $num > $counterFile");
//用函数完成写入
$fp=fopen($counterFile, "w");
fputs($fp, "$num");
fclose($fp);
}

//!!!!!!!移到前面去了 if (!file_exists($counterFile)) {
// exec( "echo 0 > $counterFile");
}

displayCounter($counterFile);

?>
</body>
</html>

net_wolf 2000-03-21
  • 打赏
  • 举报
回复
上面的程序没有判断counter.txt文件不存在的情况。自己加上就可以了!
net_wolf 2000-03-21
  • 打赏
  • 举报
回复
<?
#读取文件
$fp=fopen("counter.txt","r+");
$num=fgets($fp,10);
rewind($fp);
$num++;
fputs($fp,$num);
if($num<10)$num="00".$num;
else $num="0".$num;
fclose($fp);

#输出图形
Header("Content-type:image/gif");
//dl("php3_gd.dll");
$img=imagecreate(350,30);
$bg=ImageColorAllocate($img,0,0,0);
$fg=ImageColorAllocate($img,255,255,255);
$nu=ImageColorAllocate($img,200,225,255);
$mo=ImageColorAllocate($img,255,120,120);
ImageString($img,5,5,6,"Welcome,you're the people!",$fg);
ImageString($img,5,175,6,$num."th",$nu);
ImageArc($img,320,9,20,20,35,190,$mo);
ImageGif($img);
ImageDestroy($img);
?>
简单的图形计数器
lingdang 2000-03-17
  • 打赏
  • 举报
回复
还是不行呀!不知道有这么多人说PHP的长PHP的短,难道 
都是空对空吗??有没有的是干 实例的!
lingdang 2000-03-16
  • 打赏
  • 举报
回复
唉,各位大哥大,还是不行呀,调用的话会死机呀
唉,我的是PWS+PHP4。0的了
我看是说不清楚了,你们那位也是WINDOWS下的PHP
能不能把你的PHP程序,不管有多简单,有多。。。
请你发我一份好吗??
我真的很想学PHP
可是网上的资料很少,就是有,也是FOR LINUX的,我这单机总不可能格了装LINUX吧
我的E-MAIL是
hua_cheng@263.net
谢谢了,谢谢
希望你们能帮帮我!
   一个PHP的爱好者!
net_wolf 2000-03-16
  • 打赏
  • 举报
回复
抱歉,我先前用的是php3.0.15+win98+pws。
现在用的是nt+iis4.0+php4。
结果也出现先前的计数器程序不能运行。
偶发现php的文件好像只能分别打开读或写,而不能一次打开,同时读写。
偶改了一下程序,铁上来。
<?php
#######################################
//计数器
#######################################
function DisplayCounter($File){

$fp=fopen($File,"r");
$num=fread($fp,5);
fclose($fp);
$fp=fopen($File,"w");
$num+=1;
//exec("echo $num >$File");
$b=fwrite($fp,$num);
echo "<br>您是第".$num."位无聊人士\n";
fclose($fp);
}

$CounterFile="counter.txt";

if(!file_exists($CounterFile)){
$fp=fopen($CounterFile,"w");
fwrite($fp,"0");
//exec("echo 0 >$CounterFile");
}
DisplayCounter($CounterFile);

#######################################
?>



否则,偶的程序会出现:
Warning: Unable to fork [echo 0 >counter.txt] in d:\inet\www\test.php on line 21

偶也不知道为什么。就这样。
net_wolf 2000-03-15
  • 打赏
  • 举报
回复
忘了一点,偶的也出现dos窗口,98和nt下都是,估计是不治之症。
net_wolf 2000-03-15
  • 打赏
  • 举报
回复
把这一句去掉
exec( "rm -rf $counterFile");
或者换成:
exec( "deltree/y $counterFile");

谁给我加分数呀?
radish 2000-03-15
  • 打赏
  • 举报
回复
为什么不用PHP自己带的函数DELETE()呢?

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧