Relative URLs and all that mishmash...

From: Joseph Ellis (jandellis_at_cox.net)
Date: 07/30/04


Date: Thu, 29 Jul 2004 22:11:38 -0500

Hello all,

I'm having a hard time dealing with relative paths in PHP. Say I have
a directory structure that looks like:

+HOME
|
|---+SUBDIR
|
|---+IMAGES

In the HOME directory, I have a PHP script, "logo.php", which
includes:

foreach(glob("images/*.jpg") as $filename) {
        $files[] = $filename;
}

Then it goes on to pick a random .jpg file from the array for display
on a web page. This works fine.

Now, say I have a script "subdir.php" in the SUBDIR directory which
includes logo.php:

include("../logo.php");

When this subdir.php script gets past the foreach loop, I get the
following error:

Warning: array_rand(): First argument has to be an array in
C:\xampp\htdocs\new\logo.php on line 12

This tells me that the $files array is empty, and it has something to
do with subdir.php being in the SUBDIR directory rather than HOME.

Am I doing something wrong? What can I do to get logo.php to work
properly regardless of where it's being called from?

Thanks for any suggestions,
Joseph



Relevant Pages

  • Re: Is it possible to have mutable-in-place (associative-)array objects in PHP?
    ... PHP uses references for objects too - so if the arrays were ... So I don't think I'll need to make an array class ... Can you please post your proposed script on a Web site as a plain ...
    (comp.lang.php)
  • Re: PHP Mailto:
    ... foreach { ... have to create an array but I can't quite figure it out. ... I'm trying to create a PHP script that will parse my html page and send ...
    (php.general)
  • Re: Using List to get values from an array...
    ... >> I'm trying to assign values from an array to variables within my PHP ... > Instead of assigning the values from an array, ... > in your receiving PHP script: ... I used them to place values in a query string of a referral URL. ...
    (alt.php)
  • Re: Quickest way to do SQL search
    ... I am new to PHP but here are my few words on what you want to do. ... Maybe load it into a PHP array first (stored in another ... > The databse shouldn't change that often so I could have a script that ... in Java there is a method for the String object which matches ...
    (php.general)
  • Re: [PHP] PHP console script vs C/C++/C#
    ... My script is taking a longer time to execute than I want. ... I prefer to write in PHP because that is what I know best. ... This is why I am thinking about rewriting my whole script in a C language. ... Perhaps there are different methods I could be using to speed up execution. ...
    (php.general)