Jump to content

Recommended Posts

Hello, first time posting, still a newb at PHP

 

I'm really confused over how the include function is working in my code. When I type this

 

include('classes/clsMetaData.php');

 

I keep getting this

 

Warning: include(classes/clsMetaData.php) [function.include]: failed to open stream: No such file or directory in /opt/lampp/htdocs/WorkDamnit/index.php on line 3

 

Now, I know the file is there, and I know the file itself works; if I put the clsMetaData.php in the same folder as the calling file it works fine. I've got another project in my htdocs folder that uses the exact same syntax and setup, at least as far as I can tell, and it works fine. It's driving me nuts trying to figure out why it won't work.

 

I've recently switched to a linux environment; the previous project was created in windows, but it worked find once I switched all the \'s to /'s in the file names. I've also set up Eclipse with the PDT plugin as an IDE. I don't understand why doing that would cause a problem though since the old working project still works fine.

 

Does someone have an idea of what might be going on? 

Link to comment
https://forums.phpfreaks.com/topic/161232-confused-why-include-wont-work/
Share on other sites

Try using a full path to see if you can find it.

 

Such as:

include '/opt/lampp/htdocs/WorkDamnit/classes/clsMetaData.php';

 

Also, in a windows PHP envi, you can still use / instead of \. It should automatically convert them over (depending on how you have it setup if I remember correctly)

Using the full path didn't work. I'm not sure what you are asking PFMaBiSmAd, but  the file location is exactly what KingPhilip guessed, and testing-wise I get to it with this URL -> "http://127.0.0.1/WorkDamnit/index.php". Sorry for being a bit dense.

 

What's really frustrating is that while I'm coding Eclipse is clearly finding the clsMetaData.php file. After instantiating the class it gives me the dropdown of the class functions and variables I created. I'm just completely baffled as to what might be going wrong ...

If the absolute path did not work (assuing it gave the same error), you must be doing something wrong with the path or the file name. Is the capitalization of both the path and filename correct and exactly matches the path and file on the disk?

I'm pretty sure that I typed the file directory correctly. As I said, Eclipse can find the file when I'm coding. The dirname() function gave me the same error as before.

 

I did just stumble upon something that seems to work.

ini_set("include_path", "/opt/lampp/htdocs/WorkDamnit");

include('/Classes/clsMetaData.php');

 

I guessed this looking at the second error message, which I had previously ignored since I figured it was just saying it also couldn't find the file in the default lookup location.

 

Warning: include() [function.include]: Failed opening 'WorkDamnit/Classes/clsMetaData.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/WorkDamnit/index.php on line 4

 

I'm still really confused though. Why doesn't the project I created in windows then brought into linux also need that line to work? Is there a way to fix my problem that doesn't involve changing the ini settings at run time? Will adding this line cause any other problems?

Okay, I'm confused. What is the correct path to that file?

 

Is it:

 

/opt/lampp/htdocs/WorkDamnit/Classes/clsMetaData.php

/opt/lampp/htdocs/WorkDamnit/classes/clsMetaData.php

/opt/lampp/htdocs/classes/clsMetaData.php

/opt/lampp/htdocs/Classes/clsMetaData.php

 

?

 

Notice the difference in capitilization.

 

Because if the following works:

I did just stumble upon something that seems to work.

Quote

  ini_set("include_path", "/opt/lampp/htdocs/WorkDamnit");

  include('/Classes/clsMetaData.php');

 

then, include('/opt/lampp/htdocs/WorkDamnit/Classes/clsMetaData.php') in theory should work unless your current ini include path is pointing to somewhere it shouldnt.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.