Speckles Posted June 7, 2009 Share Posted June 7, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/161232-confused-why-include-wont-work/ Share on other sites More sharing options...
Philip Posted June 7, 2009 Share Posted June 7, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/161232-confused-why-include-wont-work/#findComment-850769 Share on other sites More sharing options...
PFMaBiSmAd Posted June 7, 2009 Share Posted June 7, 2009 Is WorkDamnit/index.php the main file being browsed to? Or is the main file in htdocs? Quote Link to comment https://forums.phpfreaks.com/topic/161232-confused-why-include-wont-work/#findComment-850771 Share on other sites More sharing options...
Speckles Posted June 8, 2009 Author Share Posted June 8, 2009 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 ... Quote Link to comment https://forums.phpfreaks.com/topic/161232-confused-why-include-wont-work/#findComment-851576 Share on other sites More sharing options...
PFMaBiSmAd Posted June 8, 2009 Share Posted June 8, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/161232-confused-why-include-wont-work/#findComment-851581 Share on other sites More sharing options...
MadTechie Posted June 8, 2009 Share Posted June 8, 2009 Try this include(dirname(__FILE__).'/classes/clsMetaData.php'); Quote Link to comment https://forums.phpfreaks.com/topic/161232-confused-why-include-wont-work/#findComment-851585 Share on other sites More sharing options...
Speckles Posted June 8, 2009 Author Share Posted June 8, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/161232-confused-why-include-wont-work/#findComment-851672 Share on other sites More sharing options...
Philip Posted June 8, 2009 Share Posted June 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/161232-confused-why-include-wont-work/#findComment-851676 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.