2012-08-05 116 views

回答

-1

有上php.net

http://php.net/manual/en/function.file-exists.php

<?php 
$filename = '/path/to/foo.txt'; 

if (file_exists($filename)) { 
    echo "The file $filename exists"; 
} else { 
    echo "The file $filename does not exist"; 
} 
?> 
+1

-1因爲您沒有解決如何防止在輸入路徑中出現「..」。 – sachleen 2012-08-05 13:24:45

2

這是不檢查該文件中預期的位置存在..你應該做到以下幾點安全的方式一個很好的例子。

$base  = '/expected/path/'; 
$filename = realpath($filename); 
if ($filename === false || strncmp($filename, $base, strlen($base)) !== 0) { 
    echo 'Missing file or not in the expected location'; 
} 
else { 
    echo 'The file exists and is in the expected location'; 
} 
相關問題