Hi everyone,

Simple query. I have a RSS.php file in my includes folder and in this I write out an XML file to a feeds folder. It has been working fine except when I changed the relative link used in the file_put_contents function to a root relative one. I want to do this besause I now have a need to include the rss.php file in multiply locations (and levels) of the site.

So this works:

$filename_path = '../feeds/vstudio_'.$_COOKIE['lang'].'.xml';

But this doesn't:

$filename_path = '/feeds/vstudio_'.$_COOKIE['lang'].'.xml';

I have tried using the realpath() function as well with no luck.

Anyone have any tips or advice on something else I can try. Any help much appreciated.


Many thanks,

Richard

If the "feed" folder is on the first level of your site (www.yoursite.com/feed/...)
and the deeper folder is on 5 levels, you should try this: $filename_path = '../../../../../feeds/vstudio_'.$_COOKIE['lang'].'.xml'; If the "feed" folder is not on the first level of your site (www.yoursite.com/anotherfolder/feed/...)
and the deeper folder is on 3 levels, you should try this: $filename_path = '../../../anotherfolder/feeds/vstudio_'.$_COOKIE['lang'].'.xml'; If you have too much "../", it will works anyway because it will stop at the root... $filename_path = '../../../../../../../../../anotherfolder/feeds/vstudio_'.$_COOKIE['lang'].'.xml'; I often use this method (php files, images, .pdf, etc...) and the links on multiple locations and any levels works fine.

Hey mate, how about using something like:

$_SERVER['SERVER_NAME'];

That'll give you the root directory so if it was used in conjunction with this site, it would show: http://www.daniweb.com

Is that any good?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.