samedi 17 décembre 2016

file_exists in php with if else statement else doesn't work

I'm sure this is pretty simple I searched and couldn't find exactly this type of question. this php:

<?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);
        } 

?>  

everything works, but the else statement won't run. Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire