PHP程式的錯誤,本機模擬沒錯,上傳網路後卻出現錯誤
以下2個書上的程式,上傳至網頁空間卻一直有錯誤,本機模擬並沒有錯誤~第1個程式:<? header("Refresh:5;url=showchatmsgs.php"); ?><!-- 程式範例:showchatmsgs.php --><html><body bgcolor="#FFCC99"><center><font color="red">聊天訊息</font></center><hr><small><?$chatfile = "chatroom.txt";if (!file_exists($chatfile)) { $file = fopen($chatfile, "w"); // 建立檔案 fclose($file);} else { // 顯示所有的訊息 readfile($chatfile);}?></small></body></html> 一段程式出現錯誤↓if (!file_exists($chatfile)) { $file = fopen($chatfile, "w"); // 建立檔案 fclose($file);第2個程式:<? ob_start(); ?><!-- 程式範例:chatroom.php --><html><head></head><body bgcolor="#CCFF99"><?session_start(); // 開啟Session$chatfile = 'chatroom.txt';if (isset($_POST["Clear"])) // 清除使用者 session_unregister("user");// 送出留言if(isset($_POST["Message"]) && isset($_POST["Send"])) { if(isset($_POST["Sender"])) { session_register("user"); // 註冊Session變數 $_SESSION["user"] = $_POST["Sender"]; } $msgs = "<b>".$_SESSION["user"]."</b>:"; $msgs .= stripslashes($_POST["Message"])."<br>\n"; $fdatas = file($chatfile); $file = fopen($chatfile,'w'); fputs($file, $msgs); // 寫入訊息 $i=1; while (list($linenum, $line) = each($fdatas)) { fputs($file, $line); $i += 1; if ($i >10) break; // 只寫入10行 } fclose($file);}?><form method="post" action="chatform.php"><table border="0"><? if (!session_is_registered("user")) { ?><tr><td>使用者名稱 : </td><td><input type="text" name="Sender" size="20"></td></tr><tr><td>聊天訊息: </td><td><? } else { ?><tr><td><? echo $_SESSION["user"] ?>: </td><td><? } ?><input type="text" size="50" name="Message" value=""></td></tr></table><input type="submit" name="Send" value="送出訊息"><? if (session_is_registered("user")) { ?><input type="submit" name="Clear" value="登出使用者"><? } ?></form></body></html>
Warning: fopen(chatroom.txt): failed to open stream: Permission denied in /home/httpd/vhosts/csw.com.tw/subdomains/myhome-hung/httpdocs/chatform.php on line 21
Warning: fputs(): supplied argument is not a valid stream resource in /home/httpd/vhosts/csw.com.tw/subdomains/myhome-hung/httpdocs/chatform.php on line 22
Warning: fclose(): supplied argument is not a valid stream resource in /home/httpd/vhosts/csw.com.tw/subdomains/myhome-hung/httpdocs/chatform.php on line 29
咦~
我把擁有者、群組、所有使用者都打勾了~︿"︿
忘了該選哪個...
全部打勾就可以看了耶^^
書上的說明並不多~
有一些程式都不懂~
3 個解答
- 匿名使用者2 0 年前最佳解答
因為你沒有貼出錯誤訊息
所以不能確定錯誤原因
不過我認為你遇到的問題應該是權限不足
所以無法開新檔案
若是UNIX-Like的系統
可用指令 chmod 修改存放該網頁的資料夾的權限
或是用IE的FTP在資料夾上按右鍵選內容
修改權限
"所有使用者"必需具有"寫入"的權限才不會發生錯誤
參考資料: 自己 - 2 0 年前
===>沒有檔案讀取的權限: 解決方法: chmod
Warning: fopen(chatroom.txt): failed to open stream: Permission denied in /home/httpd/vhosts/csw.com.tw/subdomains/myhome-hung/httpdocs/chatform.php on
========>錯誤原因: 找不到檔案
========>解決方法: 指定絕對路徑 ( http://xn--sesp80g/%E6%AA%94%E5%90%8D)
line 21 2005-06-06 23:37:20 補充
Warning: fputs(): supplied argument is not a valid stream resource in /home/httpd/vhosts/csw.com.tw/subdomains/myhome-hung/httpdocs/chatform.php on
========>錯誤原因: 找不到檔案
========>解決方法: 指定絕對路徑 ( http://xn--sesp80g/%E6%AA%94%E5%90%8D)(%E5%90%8C%E...
line 22 2005-06-06 23:37:33 補充
Warning: fclose(): supplied argument is not a valid stream resource in /home/httpd/vhosts/csw.com.tw/subdomains/myhome
參考資料: 靈感 - 2 0 年前
ㄆㄆ...這個還是我剛寫好ㄉ東西= =''
那個$line要改成$i
因為$line沒有任何值= =''
那一段是要設定聊天室最多可以看到10行對話.(那本書的筆誤)
其他的小問題就是自己打錯ㄌㄅ= =''