你有不匹配的引號。試試這個代碼。
$playerfileLocation = "../wp-content/gallery/playerphotos/" . $playerid . ".jpg";
if(file_exists($playerfileLocation))
echo "The file File exists";
else
echo "The file File does not exist";
更新: 其實我會建議使用下面的代碼作爲PHP時看到雙引號,它試圖分析在它之間的任何東西,這不是在這種情況下需要。這是性能上的一個小優化。
$playerfileLocation = '../wp-content/gallery/playerphotos/' . $playerid . '.jpg';
if(file_exists($playerfileLocation))
echo "The file File exists";
else
echo "The file File does not exist";
而且,只是檢查文件是否存在,如果不顯示默認圖像使用下面的代碼:
$playerfileLocation = '../wp-content/gallery/playerphotos/' . $playerid . '.jpg';
$defaultfileLocation = '../wp-content/gallery/playerphotos/default.jpg';
if (!file_exists($playerfileLocation)) {
$playerfileLocation = $defaultfileLocation;
}
這是相對路徑的工作? – 2011-12-24 04:12:58
否...頁面一旦到達if語句就停止。我在這個「測試」下方顯示的文本沒有被顯示。 – DoubleA 2011-12-24 04:21:41