0
  if (file_exists("displaytab.php")) {
    $sys = fopen("displaytab.php", "r+");
    system(".\displaytab.php"); }

I've tried to run the script in displaytab.php that I saved in the directory of my local server, I searched for the correct signature of system() and I used it, but it doesn't work. Am I using the wrong command or the right one but in the wrong way?

3
  • Don't do the fopen first. And how can you tell it isn't executing? What are you expecting when it works? Commented May 8, 2018 at 22:22
  • And does it work if from the command line you do .\displaytab.php? Are you sure the file is actually executable? Commented May 8, 2018 at 22:24
  • What do you want to achieve with that code? Commented Oct 1, 2020 at 9:49

3 Answers 3

1

Wrong command. All you need to do is

include 'displaytab.php';
Sign up to request clarification or add additional context in comments.

2 Comments

No! include includes the specified file at the current point, as if the code was present in the current file. So it gets parsed/executed like the code in the current file (and with the current scope)
Unless you are actively wanting to execute it as a command line script, not as part of the server application (so it won't produce output to the page, for example). Which I don't recommend - most hosting set-ups lock down that sort of execution on security grounds, apart from anything else.
0

the php system function accepts a command to be executed you could try :

<?php
   $file = 'file.php';
   system('php '.$file);
 ?>

Comments

0

To include php file inside another php file you should use require() or include().

The different between this two functions is if you use require() and the file you invite contain fatal erros will block the script to execute but if you use include() the file execute however if contain erros.

And there is to other functions require_once() and include_once they do the same thing but if you want your file invite one time in php file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.