I already saw this question, but it didn't work for me.

What I need to do is to check whether a file exists, in PHP, without knowing the extension. I use this code:

<?php 
if (count(glob("/database/".$_REQUEST['thetitle'].".*")) == 0) {
echo 'true';
} else {
echo 'false';
}
?>

EDIT: Maybe it's relevant saying that the script is located in

[root]/functions/validatefilename.php

and the database in

[root]/database/

But it always returns false, no matter what the filename ($_REQUEST['thetitle']) is.

有帮助吗?

解决方案

try:

count(glob("./database/".$_REQUEST['thetitle'].".*"))

其他提示

Looks to me like it works fine except that you should be specifying the full path:

if (count(glob( "/path/to/" . "database/" .$_REQUEST['thetitle']. ".*")) == 0) {
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top