0

I need to check if a file exist but the system cannot find the file, it may be because the code is ending the $var with .php I dont know. Here is the code

  $thefile=$_POST['files'];
    if (file_exists('/infrastructure/datacenter/'.$thefile.'.php'))
{include('infrastructure/datacenter/'.$thefile.'.php');}

Any idea why the file cannot be found? Because the file really exist

the file name in the test is 2001.php and it does exist but php says it does not exist

SOLVED

There was a missing / in the include second path

NICALANICA
  • 35
  • 5
  • 1
    anything from http://php.net/manual/en/function.error-reporting.php ? you may have to update your post to include the HTML/form for this. – Funk Forty Niner Jul 24 '17 at 20:40
  • you start one of the file paths with `/` and the other without, that have anything to do with it? – WheatBeak Jul 24 '17 at 20:41
  • 1
    well what's the actual name of the file on disk. How can you "not know" whether it's because the code is appending ".php" to it. Does the file you want to find end with ".php"? What's the contents of "$thefile"? Why do you start one of your paths with "/" but not the other? BTW allowing a postback to control what PHP files get executed strikes me as a massive security disaster waiting to happen. – ADyson Jul 24 '17 at 20:41
  • Yeah the file name in the test is 2001.php and it does exist but php says it does not exist – NICALANICA Jul 24 '17 at 20:42
  • Is the file in the same directory as the file that contains this code? – WheatBeak Jul 24 '17 at 20:43
  • Yeah I will try this with the /in path – NICALANICA Jul 24 '17 at 20:44
  • yes its in the same directory thats why I am sure it exist – NICALANICA Jul 24 '17 at 20:44
  • It was the path / as WheatBeak said – NICALANICA Jul 24 '17 at 20:46
  • 1
    you should be very very careful doing what you are doing, if you slip up you can expose other files on your system or even let php include a remote file! – cmorrissey Jul 24 '17 at 20:48

2 Answers2

1

You have the if statement checking an absolute path, while your include statement is relative.

tanghe
  • 80
  • 5
0

SOLVED

There was a missing / in the include second path

NICALANICA
  • 35
  • 5