PHP Paths

User avatar
Cah
3StarLounger
Posts: 293
Joined: 26 Mar 2010, 10:53

PHP Paths

Post by Cah »

Happy New Year!

I use the following function to pull a random image to put on a page through an included file:

Code: Select all

function ranget($path = '/random', $type)
{
    $files = glob($path . $type);
    $file = array_rand($files);
    return $files[$file];
}
I access the function like this:

Code: Select all

$ranpic = "http://".$_SERVER['HTTP_HOST'].substr(ranget($_SERVER['DOCUMENT_ROOT']."/random/main",'/*.??g'),28);
I found it necessary to use the substr in order to get glob to find the directory. It works on my live site but on my local computer I get an error. I think this is because the path length of the file location on my local file is different from the one on the live site. It must have something to do with php and relative paths. Does anyone know anything about relative paths and php? I would like to be able to get everything to work both on my actual site and my local computer. Thanks

User avatar
HansV
Administrator
Posts: 78238
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: PHP Paths

Post by HansV »

I fear we don't have PHP experts, sorry!
Best wishes,
Hans