在php中编写文件时出错

时间:2013-09-03 09:58:46

标签: php

我有这个PHP代码:

<?php
echo ("Setting up data..."); 
$today = date("YmdHi");
$wtoday = $today
$im = $_GET["im"];
$fim = "tips/$today/im.txt";
$fwtoday = "tips/$today/today.txt";
?>
<?php
$fp = fopen ($fwtoday, "w"); # w = write to the file only, create file if it does not exist, discard existing contents 
if ($fp) { 
    fwrite ($fp, $wtoday); 
    fclose ($fp); 
    echo ("Today written"); 
} 
else { 
    echo ("Today was not written"); 
}
?>
<?php
$fp = fopen ($fim, "w"); # w = write to the file only, create file if it does not exist, discard existing contents 
if ($fp) { 
    fwrite ($fp, $im); 
    fclose ($fp); 
    echo ("Im written"); 
} 
else { 
    echo ("Im was not written"); 
}
?>

Finaly今天我不写,我的错误在哪里? 我不认为这与文件权限有关。 我忘记在帖子中写下$ fwtoday = "tips/$today/today.txt";,但仍无效。

3 个答案:

答案 0 :(得分:2)

$wtoday = $today

缺少分号,解析错误。

那个asice,你似乎试图打开一个存储在变量$fwtoday中的文件名,你似乎没有在任何地方定义过。

答案 1 :(得分:2)

将这些行插入文件的前面,并分享给定的错误:

error_reporting(E_ALL);
ini_set('display_errors','On');

答案 2 :(得分:0)

我没有看到 $ fwtoday 的定义。你也不需要这样做:

?>
<?php