Include_once problems

Can't seem to find a certain file

Page 1 of 1

11 Replies - 11590 Views - Last Post: 12 May 2008 - 11:16 PM Rate Topic: -----

#1 thor78  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 121
  • Joined: 06-May 08

Include_once problems

Posted 11 May 2008 - 10:37 PM

I have this weird problem where I get this error:

Warning: include_once(../DAL/ServiceRequestDataAccess.php) [function.include-once]: failed to open stream: No such file or directory in C:\wamp\www\MSRS\BLL\NewRequestFunctions.php on line 3

My file structure is as follows:

MSRS->DAL/Data Access classes and functions
->BLL/Business Logic classes and functions
->Example.php

As shown in the error message, ServiceRequestDataAccess.php is located in the DAL folder, and it's calling page is the NewRequestFunctions.php in the BLL folder. My problem now is that NewRequestFunctions can't seem to locate ServiceRequestDataAccess.

Sample code from NewRequestFunctions
<?php
	session_start();
	include_once("../DAL/ServiceRequestDataAccess.php");
?>



This is weird because I have another code file located in BLL named EvaluateLogin.php with the following:
<?php 
	session_start();
	include_once("../DAL/EmployeeDataAccess.php");
	include_once("../DAL/DepartmentDataAccess.php");
	include_once("../DAL/SectionDataAccess.php");
?>



and they work perfectly. Also I have an include_once("dbconnect.php") statement in all Data Access code files. My dbconnect is located in the DAL folder as well. Another weird thing is when I move dbconnect and ServiceRequestDataAccess to the BLL folder, the web app works fine.

Please help.

Is This A Good Question/Topic? 0
  • +

Replies To: Include_once problems

#2 joeyadms  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: Include_once problems

Posted 11 May 2008 - 11:37 PM

Is the NewRequestFunctions page being called directly or included from another page. Other than that, just make sure spelling is correct, and that the file is indeed actually there, I maybe missing something.

To troubleshoot you could also try an absolute path.
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5394
  • View blog
  • Posts: 27,388
  • Joined: 10-May 07

Re: Include_once problems

Posted 12 May 2008 - 12:04 AM

Is it possible that the file system is case sensitive?
Was This Post Helpful? 0
  • +
  • -

#4 thor78  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 121
  • Joined: 06-May 08

Re: Include_once problems

Posted 12 May 2008 - 12:13 AM

I already tried the absolute path, e.g. http://localhost/MSR...eDataAccess.php, and yes, the files exist in the folders.

The weird thing is that I never called the functions within the NewServiceFunction.php code file yet. I just included it in one of the presentation pages.

View Postno2pencil, on 12 May, 2008 - 12:04 AM, said:

Is it possible that the file system is case sensitive?


Sorry for double posting, I'm using Zend and it's on autocomplete and I copy-pasted the file names to reduce errors.

This post has been edited by thor78: 12 May 2008 - 12:11 AM

Was This Post Helpful? 0
  • +
  • -

#5 joeyadms  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: Include_once problems

Posted 12 May 2008 - 12:28 AM

When I mean absolute, you have to use the file system path, ex. c:\blah , also Windows is not case sensitive.

Try the absolute path, copied from windows explorer or something, also try using this
$filename = "C:\wamp\www\MSRS\DAL\ServiceRequestDataAccess.php";
die(file_exists($filename));



should come out 1 if it exists, 0 if not, or if safe mode is blocking it.
Was This Post Helpful? 0
  • +
  • -

#6 thor78  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 121
  • Joined: 06-May 08

Re: Include_once problems

Posted 12 May 2008 - 12:34 AM

Well it died, meaning it exists. But I still can't find out why it can't see through the logical name. :(
Was This Post Helpful? 0
  • +
  • -

#7 joeyadms  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: Include_once problems

Posted 12 May 2008 - 12:44 AM

when it died, did it output a 1, if so , thats good. But relative paths are difficult. Try to modify the $filename string.

try something like
$filename = '../DAL/ServiceRequestDataAccess.php';
die(file_exists($filename));



If that fails , then try ./DAL/ServiceRequestDataAccess.php , or ../../DAL etc.

There is something strange going on here, or either it's right in front of us.
Was This Post Helpful? 0
  • +
  • -

#8 thor78  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 121
  • Joined: 06-May 08

Re: Include_once problems

Posted 12 May 2008 - 01:20 AM

Yep the output was 1 when I tried
$filename = "C:\wamp\www\MSRS\DAL\ServiceRequestDataAccess.php";
die(file_exists($filename));



But did not output anything when I tried this:
$filename = '../DAL/ServiceRequestDataAccess.php';
die(file_exists($filename));



AND fortunately using
include_once("./DAL/ServiceRequestDataAccess.php");



worked. Thanks a lot! :D

And by the way, how different are the "./" and the "../" in terms of relative path seeking? A bit confusing.

This post has been edited by thor78: 12 May 2008 - 01:22 AM

Was This Post Helpful? 0
  • +
  • -

#9 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5394
  • View blog
  • Posts: 27,388
  • Joined: 10-May 07

Re: Include_once problems

Posted 12 May 2008 - 01:26 AM

View Postthor78, on 12 May, 2008 - 04:20 AM, said:

And by the way, how different are the "./" and the "../" in terms of relative path seeking? A bit confusing.

When you view a directory listing you will see that there is always two directories.

Dot & double dot.

A single dot always represents current directory, & the double dots always represents the previous directory.

With that in mind, in a Windows enviornment:

C:\windows> cd ..
will take you to the previous directory. C:\

C:\windows> dir ./win.exe
You are looking for win.exe in the current directory.
Was This Post Helpful? 0
  • +
  • -

#10 thor78  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 121
  • Joined: 06-May 08

Re: Include_once problems

Posted 12 May 2008 - 01:46 AM

Thank you again! :)
Was This Post Helpful? 0
  • +
  • -

#11 joeyadms  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: Include_once problems

Posted 12 May 2008 - 01:51 AM

Good deal, glad to see it's working.
Was This Post Helpful? 0
  • +
  • -

#12 thor78  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 121
  • Joined: 06-May 08

Re: Include_once problems

Posted 12 May 2008 - 11:16 PM

Still getting problems with './' and '../', but I found a better solution here

Instead of guessing our current working directory or it's location relative to root, we can use $_SERVER['DOCUMENT_ROOT']. An example output would be C:\wamp\www.

So putting it together in a require_once/include_once statement:
require_once($_SERVER['DOCUMENT_ROOT'] . "/path/to/include.php");



Works like a charm. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1