Jump to content

[SOLVED] PHP Include Troubles / setting paths, etc. Please Help!!


tabco2

Recommended Posts

I've came across a somewhat unique situation that I'd like to be able to do with PHP.

The site is powered on WordPress.  This will not make a difference, because all of the coding is being done in the template files, which can accept all raw code.

 

Here's what I wanna do:

mysite.com/i/ < has a PHP image hosting script installed (Keep in mind, index.php here includes files in other directories within /i/.  Ex. mysite.com/i/index.php calls for includes/file.php  &  includes/file.php calls for files.

 

mysite.com/wp-content/themes/classic/file.php < I want the image script from mysite.com/i/ to be included & functional here

 

I've tried a variety of include methods, path settings, etc. from various forums and of course the php include manual.

 

Help please?

 

Thanks.

Link to comment
Share on other sites

So, your saying you have a file...

 

mysite.com/wp-content/themes/classic/file.php

 

And from that file you wish to include a file contained within....

 

mysite.com/i/

 

?

 

<?php include $_SERVER['DOCUMENT_ROOT'] . '/i/filename.php'; ?>

Link to comment
Share on other sites

So, your saying you have a file...

 

mysite.com/wp-content/themes/classic/file.php

 

And from that file you wish to include a file contained within....

 

mysite.com/i/

 

?

 

<?php include $_SERVER['DOCUMENT_ROOT'] . '/i/filename.php'; ?>

 

Here is the real url: http://classicia.com/image-hosting-sharing/

 

Thank you for the reply.  I tried the code & i get this error: 

Commons.inc.php is located: http://mysite.com/i/includes/commons.inc.php

 

Warning: main(includes/configs.inc.php) [function.main]: failed to open stream: No such file or directory in /nfs/c02/h05/mnt/24150/domains/classicia.com/html/i/includes/commons.inc.php on line 36

 

Fatal error: main() [function.require]: Failed opening required 'includes/configs.inc.php' (include_path='.:/usr/local/php-4.4.8-1/share/pear') in /nfs/c02/h05/mnt/24150/domains/classicia.com/html/i/includes/commons.inc.php on line 36

Link to comment
Share on other sites

By using $_SERVER['DOCUMENT_ROOT'] your are setting the path from the root of your site.

 

You would use

 

<?php

include($_SERVER['DOCUMENT_ROOT'].'/i/includes/commons.inc.php');
?>

 

This will call it from any page whatsoever. I have found any time your using an include, you should call it using this type of path to avoid the errors.

 

*edit*

 

I just looked at the path in the error, you may need to use /html/i/includes/commons.inc.php.

 

To determine for sure, just echo $_SERVER['DOCUMENT_ROOT']; and see what path you get, then append the path you need to it.

 

Nate

Link to comment
Share on other sites

By using $_SERVER['DOCUMENT_ROOT'] your are setting the path from the root of your site.

 

You would use

 

<?php

include($_SERVER['DOCUMENT_ROOT'].'/i/includes/commons.inc.php');
?>

 

This will call it from any page whatsoever. I have found any time your using an include, you should call it using this type of path to avoid the errors.

 

*edit*

 

I just looked at the path in the error, you may need to use /html/i/includes/commons.inc.php.

 

To determine for sure, just echo $_SERVER['DOCUMENT_ROOT']; and see what path you get, then append the path you need to it.

 

Nate

 

http://classicia.com/image-hosting-sharing/

 

Nate. It ended up that the path needed to be the file directly, for whatever reason. So it's just "commons.inc.php"

 

However, here is the error that followed.

 

Fatal error: Cannot redeclare clean_url() (previously declared in /nfs/c02/h05/mnt/24150/domains/classicia.com/html/wp-includes/formatting.php:1142) in /nfs/c02/h05/mnt/24150/domains/classicia.com/html/i/includes/functions_base.inc.php on line 50

 

What does this mean? - Or is this digging too far, and there is another solution?

 

Thanks for the help.

Link to comment
Share on other sites

I took care of that, and now it brings me to this error.  I know this is generated by the image host script.  I looked around in the settings and can't seem to figure out what the path settings should be for it.  I tried a variety of paths and nothing seems to work.

 

The tpl_uploader.php is in the exact location of the error though, so it has to be thinking its in a different root directory

 

The template file 'templates/default/tpl_uploader.php' does not exist.

Link to comment
Share on other sites

Well, you can fight with paths and such or you can learn to use $_SERVER['DOCUMENT_ROOT'] properly and avoid all path errors. I fought with include paths numerous times before discovering this little gem.

 

If you include a file as include('your_file.php') on a page in /some/directory  and then try to call it the same way in a file located in /some/other/directory it will return an error. use $_SERVER['DOCUMENT_ROOT'] and it will not matter where the file calling the include lives because server doc_root is kinda like html's /start/at/root  syntax.

 

Your link that you provided gives a 404 error.

 

We can only speculate as to why your pages are ending up at the /i/ dir without seeing any code.

 

Nate

Link to comment
Share on other sites

Nate,

 

Thank you for the help. I did learn how to use the Document Root function, and it works well.  However, after I fix all the directories to function properly I end up with other errors.

 

I'm working within wordpress, so it gives it a little more difficulty.  I really want this to play out smooth though, its important to me.

 

http://classicia.com/images/ < current url & error

 

I'm getting on a 16 hour flight in a few minutes so if my reply is slow, you'll know why. But i'd like to get this sorted out.

 

Thank you again.

Link to comment
Share on other sites

The errors are because of your paths.

 

try

<?php 
include($_SERVER['DOCUMENT_ROOT'].'/html/i/includes/commons.inc.php');
?>

 

if that don't work then try 

 

<?php 
include($_SERVER['DOCUMENT_ROOT'].'/i/includes/commons.inc.php');
?>

 

If neither of those work, then do this and post the results....

 

<?php
echo $_SERVER['DOCUMENT_ROOT'];
?>

Link to comment
Share on other sites

The errors are because of your paths.

 

try

<?php 
include($_SERVER['DOCUMENT_ROOT'].'/html/i/includes/commons.inc.php');
?>

 

if that don't work then try 

 

<?php 
include($_SERVER['DOCUMENT_ROOT'].'/i/includes/commons.inc.php');
?>

 

If neither of those work, then do this and post the results....

 

<?php
echo $_SERVER['DOCUMENT_ROOT'];
?>

 

Ok, I went through all the errors & fixed all the paths it was wanting.  And it's brought me to one other dilemma.

 

http://classicia.com/images/

 

When you click the links on the uploader script, it goes directly to the specified page directly, leaving the wordpress page in which the script is included into...

 

Any ideas on how to keep it within that page? That might require one that's a wordpress experienced person...  Let me know if you have any ideas there.  Thanks for the help, and I'm trying to do everything possible to figure it out in between your replies.

Link to comment
Share on other sites

Finally. It's not fixed, but I've confirmed that it is a wordpress issue.

 

Thanks a MILLION for the help, especially with the directory specific issues.  I should be able to figure out everything from here.

 

Thanks again!

Link to comment
Share on other sites

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.