所以這裏是我的代碼不斷打我的錯誤信息,有權限擺弄,但沒有運氣,任何想法?PHP文件寫入 - 錯誤信息每次
<?php
//create variables
$first_name = (int) $_POST['first_name'];
$last_name = (int) $_POST['last_name'];
$document_root = $_SERVER['/var/www'];
$date = date('H:i, jS F Y');
?>
<DOCTYPE html>
<html>
<head>
<title>We get the message...</title>
</head>
<body>
<h1>We get the message . . .</h1>
<?php
$output_string = $date."\t".$first_name.$last_name." \t".$message."\n";
@$fp = fopen("$document_root-messages.txt", 'w+');
if (!$fp) {
echo "<p>apologies</p>";
exit;
}
flock($fp, LOCK_EX);
fwrite($fp, $output_string, strlen($output_string));
flock($fp, LOCK_UN);
fflush($fp);
fclose($fp);
echo "<p>message written.</p>";
?>
</body>
</html>
我剛開始學習PHP因此它可能是很簡單的東西,但我一直在抓我的頭了大約一個小時,仍然沒有拿出一個解決方案。
您確定您對文件夾具有所需的權限嗎? – PekosoG
看起來您正在寫入名爲'/ var/www-messages.txt'的文件。我假設你的意思是'/ var/www/messages.txt'? '$ fp = fopen(「$ document_root/messages.txt」,'w +');'並注意我刪除了@ @錯誤抑制。 –
如果這實際上是你的意圖,那麼允許Web服務器直接寫入'/ var'是非常危險的。即使在'/ var/www'內部寫入也是相當危險的,因爲所有其他文件都明確需要被Web服務器用戶設置爲不可寫。 –