我有这个代码,它有一个错误,但我不明白我出错的地方。有人可以帮忙吗?问题是,我试图显示一个特定的图像来腐蚀文本文件的内容。我觉得我有这部分排序,但是当涉及到显示图像总有一个错误(例如,它永远是绿色的,即使如果statment说otherwize.Here是代码:PHP - 如果和其他语句
<?php
if (empty($_GET['unit'])) {
$output="Please Enter A Unit Number";
echo $output;
}
else {
$filepathhalf = "/data/";
$file = "false";
$date = date("Ymd");
$unitnum = $_GET['unit'];
$ext = ".txt";
$filepath = $filepathhalf.$unitnum.$date.$ext;
echo $filepath;
echo $file;
if(file_exists($filepath))
{
$fh = fopen($filepath, 'r');
$file = fread($fh, 5);
fclose($fh);
}
echo $file; //This echo comes back as false as set but the green.png image still displays.
if ($file = "true ")
{
echo "<img src=\"images/green.png\" width=\"15\" height=\"15\" />";
}
else
{
echo "<img src=\"images/red.png\" width=\"15\" height=\"15\" />";
}
echo $_GET['unit'];
}
?>
三江源指点大家指出了这一点:)生病接受第一次的答案只是因为我只能accpept一个.. – Nick 2012-07-13 05:27:15
虽然你不应该在一个文件中混合的担忧,不管怎么说,你可能会发现PHP输入和输出HTML输出有利:'if($ file):?> Dan 2012-07-13 05:56:39