Jump to content

Script doesn't run ok when is executed from another folder.


Montha
 Share

Recommended Posts

Hi, to all.

I've a code typed in php on my index.php, that code calls another file engine.php that is in another sub directory, that file reads a directory searching for *.txt, open each file and search/count for a xml label and show the results.

The problem is that when i execute the engine.php from the directory /process (in this directory i store all my functions) the code doesn't execute correctly, but when i move the engine.php to the directory where the files to count are it executes and shows all the information correctly. What could be the problem?

Thanks.

Link to comment
Share on other sites

We are not psychic.  Most likely you have a pathing problem with your code.  Paste relevant portions or the script in its entirety so that we can see what you've done.  Make sure to use the code button <> when you paste the code so formatting is preserved.

Link to comment
Share on other sites

5 hours ago, Montha said:

The problem is that when i execute the engine.php from the directory /process (in this directory i store all my functions) the code doesn't execute correctly, but when i move the engine.php to the directory where the files to count are it executes and shows all the information correctly. What could be the problem?

 

If you're using relative paths in engine.php and calling that file directly, moving it to a subdir will break the includes.  In your example, if engine.php needed functions.php, in root it would look like

 

include('./includes/functions.php');

the single dot meaning start in the current directory

whereas, if it were in /process, it would look like

include('../includes/functions.php');

the two dots meaning move up to the parent directory.

Share your directory structures and include code for more relevant suggestions.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.