Page 1 of 1

relative filenames in scripts

Posted: Mon Mar 28, 2011 2:32 pm
by jude.hanlon
The scripts that I'm running using phpscheduler would ideally use a common script to access the database, but both relative and absolute pathnames aren't recognised: I get...

Code: Select all

Warning: require(../../jude/admin/vars2.php) [function.require]: failed to open stream: No such file or directory in C:\Inetpub\wwwroot\jude\appointments\requester-export.php on line 4

Fatal error: require() [function.require]: Failed opening required '../../jude/admin/vars2.php' (include_path='.;C:\php5\pear') in C:\Inetpub\wwwroot\jude\appointments\requester-export.php on line 4

I've tried several permutations, but each time no joy.
phpscheduler is in the root directory
the script is in /jude/appointments/export-requesters.php
the common access file settings are in /jude/admin/vars2.php (as above)

As a short-term fix I've included the DB access info in each file, but I'd prefer to use the relative pathnames if poss so that when copying from test to live I don't have to change/check each file for such mundane info...

Any ideas?
thanks!
jude

Re: relative filenames in scripts

Posted: Mon Mar 28, 2011 2:47 pm
by davidgwalker
Hi Jude,

If you add it as a remote script does it fire?

More details here:
viewtopic.php?f=1&t=579

Cheers

Dave

Re: relative filenames in scripts

Posted: Tue Mar 29, 2011 7:32 am
by jude.hanlon
Hi Dave

The script itself fires, but required files within the script can't be accessed, according to the error message.

The first few lines of the script are...

Code: Select all

<?php
session_start();
require '../../jude/admin/vars2.php';

$filename="requester-list.csv";
$outfile=fopen($filename,"w");


...and it falls over with the error message I previously posted at line 3
this file is in /jude/comps
phpscheduler is in /phpjobscheduler
the file I want to "require" is in /jude/admin

the path is currently set as though the working directory is phpjobscheduler/pjsfiles, which is my current best guess at getting this working as the error message is at least showing me the correct filepath even though it's saying it can't find/open the file...

cheers
jude

Re: relative filenames in scripts

Posted: Tue Mar 29, 2011 7:43 am
by davidgwalker
Try this:

Code: Select all

<?php
session_start();
chdir("../../jude/admin/");
require 'vars2.php';
...