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.

Était-ce utile?

La solution

try:

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

Autres conseils

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) {
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top