Question

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.

Was it helpful?

Solution

try:

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

OTHER TIPS

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) {
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top