我想检查jpeg我的服务器上是否存在文件。但是,当我检查它时,返回值为 false。
clearstatcache();
// the $img variable is dynamically got from $split[1] which is something like image.jpeg" />
$img = str_replace('"','',$split[1]); // remove double quotes
$img = str_replace('/>','',$img); // remove img end tag
$img = str_replace(' ','',$img); // remove spaces
$filename = "uploads/image.jpeg"; // original file name
$fn = "uploads/".$img; // file name with dynamic variable in it
if(file_exists($fn)){
echo "yes";
}else{
echo "no";
}
// Check if the two strings are the same and they are
if($fn == $filename){
echo "same";
}
原始静态文件名返回yes,而动态文件名返回no。我检查并safe_mode在off我的服务器上,两个变量($fn和$filename)完全一样。如果我只是简单地$img等于image.jpeg没有任何str_replace它也会回馈true并回显yes。
总的来说,我不知道变量有什么问题$img,如果变量相同,为什么它会给我两个不同的结果?