我有這個代碼,它有一個錯誤,但我不明白我出錯的地方。有人可以幫忙嗎?問題是,我試圖顯示一個特定的圖像來腐蝕文本文件的內容。我覺得我有這部分排序,但是當涉及到顯示圖像總有一個錯誤(例如,它永遠是綠色的,即使如果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