file_exists永远不会在if语句中返回false

时间:2016-12-18 05:42:32

标签: php if-statement file-exists

一切正常,但else语句不会运行。

<?php
$localhost  = "http://localhost";
/* $target_dir = $_SERVER['DOCUMENT_ROOT'].'/uploadmod/uploads/'; 
 */

$target_dir = "uploads/";

if ($handle = opendir("$target_dir")) {

    while (false !== ($file_name = readdir($handle))) {
        if ($file_name != "." && $file_name != "..") {
            preg_replace('/\\.[^.\\s]{3,4}$/', '', $file_name);

            if (file_exists($target_dir.$file_name)) {
                echo "<img src=$target_dir". $file_name. ' ' . 'width=25%' . ' ' . 'height='."><br />";
                echo "<a href=$localhost/uploadmod/image.php?cmd=viewimage&file_name=$file_name".">View this image</a><br />";
                echo "<a href=$localhost/uploadmod/delete_image.php?cmd=delete&file_name=$file_name".">delete</a><br /><br />";
            } else {
                echo "no image found";
            }
        }

    }
    closedir($handle);
} 

?> 

0 个答案:

没有答案