Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
02-21-2010, 01:28 PM #1
Creating a PHP Library - Properly linking folders
I've got a project I'm working on which requires some code that is going to end up being very reusable. In order to get the most value out of my code, I want to store it 100% separate from my project.
The library itself is basically two classes + some images. How can I set things up so that in any other project, I can do something like
and everything will fall into place? This also includes using those images. Right now, in the library, I simply say "images/image.png". The problem: That path is relative to the file that included the library, not the library. I want to store the images as part of the library.
02-21-2010, 02:13 PM #2
- Join Date
- Dec 2008
- Thanked 0 Times in 0 Posts
use require_once(""); or include_once(""); ?
I guess you could use absolute links like "http://example.net/libs/mylib/mylib.php"
But what you've said
if I've understood your question, i can't see you having a problem?require_once ("../libs/mylib/mylib.php")
02-21-2010, 02:53 PM #3
That would work if I only wanted to use the library in one place or on one server. I'm having trouble because I want to be able to use this code anywhere on any different server without having to change much more than a configuration path or something.
Note that the include of mylib.php can change. However, mylib.php includes several other files that are part of the library. Because those paths are relative to the file that included mylib.php, it will often be wrong. For example, if I put a demo.php file in the mylib directory and then also try to use the library from a different folder, it won't work in both cases.