Welcome to Dream.In.Code
Click Here
Getting PHP Help is Easy!

Join 118,861 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 1,687 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Include_once problems

 
Reply to this topicStart new topic

Include_once problems, Can't seem to find a certain file

thor78
post 11 May, 2008 - 10:37 PM
Post #1


D.I.C Head

Group Icon
Joined: 6 May, 2008
Posts: 106



Dream Kudos: 50
My Contributions


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

<?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

<?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.
User is offlineProfile CardPM

Go to the top of the page


joeyadms
post 11 May, 2008 - 11:37 PM
Post #2


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 145



Thanked 6 times

Dream Kudos: 600
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 12 May, 2008 - 12:04 AM
Post #3


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 5,522



Thanked 36 times

Dream Kudos: 2350

Expert In: Goofing Off

My Contributions


Is it possible that the file system is case sensitive?
User is online!Profile CardPM

Go to the top of the page

thor78
post 12 May, 2008 - 12:13 AM
Post #4


D.I.C Head

Group Icon
Joined: 6 May, 2008
Posts: 106



Dream Kudos: 50
My Contributions


I already tried the absolute path, e.g. http://localhost/MSRS/DAL/ServiceDataAccess.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.

QUOTE(no2pencil @ 12 May, 2008 - 12:04 AM) *

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
User is offlineProfile CardPM

Go to the top of the page

joeyadms
post 12 May, 2008 - 12:28 AM
Post #5


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 145



Thanked 6 times

Dream Kudos: 600
My Contributions


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
CODE

$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.
User is offlineProfile CardPM

Go to the top of the page

thor78
post 12 May, 2008 - 12:34 AM
Post #6


D.I.C Head

Group Icon
Joined: 6 May, 2008
Posts: 106



Dream Kudos: 50
My Contributions


Well it died, meaning it exists. But I still can't find out why it can't see through the logical name. sad.gif
User is offlineProfile CardPM

Go to the top of the page

joeyadms
post 12 May, 2008 - 12:44 AM
Post #7


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 145



Thanked 6 times

Dream Kudos: 600
My Contributions


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
CODE

$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.
User is offlineProfile CardPM

Go to the top of the page

thor78
post 12 May, 2008 - 01:20 AM
Post #8


D.I.C Head

Group Icon
Joined: 6 May, 2008
Posts: 106



Dream Kudos: 50
My Contributions


Yep the output was 1 when I tried
php

$filename = "C:\wamp\www\MSRS\DAL\ServiceRequestDataAccess.php";
die(file_exists($filename));


But did not output anything when I tried this:
php

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


AND fortunately using
php

include_once("./DAL/ServiceRequestDataAccess.php");


worked. Thanks a lot! biggrin.gif

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
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 12 May, 2008 - 01:26 AM
Post #9


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 5,522



Thanked 36 times

Dream Kudos: 2350

Expert In: Goofing Off

My Contributions


QUOTE(thor78 @ 12 May, 2008 - 04:20 AM) *

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.
User is online!Profile CardPM

Go to the top of the page

thor78
post 12 May, 2008 - 01:46 AM
Post #10


D.I.C Head

Group Icon
Joined: 6 May, 2008
Posts: 106



Dream Kudos: 50
My Contributions


Thank you again! smile.gif
User is offlineProfile CardPM

Go to the top of the page

joeyadms
post 12 May, 2008 - 01:51 AM
Post #11


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 145



Thanked 6 times

Dream Kudos: 600
My Contributions


Good deal, glad to see it's working.
User is offlineProfile CardPM

Go to the top of the page

thor78
post 12 May, 2008 - 11:16 PM
Post #12


D.I.C Head

Group Icon
Joined: 6 May, 2008
Posts: 106



Dream Kudos: 50
My Contributions


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:
php

require_once($_SERVER['DOCUMENT_ROOT'] . "/path/to/include.php");


Works like a charm. smile.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/13/08 01:47AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month