SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quickie PHP script worked once...

    I snaffled a little script to print the contents of a directory on the screen
    Code PHP:
    <?php
    if ($handle = opendir('.')) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                echo "$file\n";
            }
        }
        closedir($handle);
    }
    ?>
    Then altered it to look in an images directory and load this as a background with CSS. Worked great--once. Then it wouldnt work again.

    If I view source, I see the xHTML/CSS dynamically change with the file name I swap into the directory.

    What gives?
    Xtian

    Also I used the WebDev toolbar to turn off Cache.
    Dinopad R40 - F15/XP
    APACHE 2
    MYSQL 5
    PHP 5

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use the full path to the directory:

    PHP Code:
    <?php

    $handle 
    opendir('c:\apache\htdocs\test')
    my mobile portal
    ghiris.ro

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xtiansimon View Post
    Then altered it to look in an images directory and load this as a background with CSS. Worked great--once. Then it wouldnt work again.
    Post the code you're -actually- having trouble with (not the example you started from), and perhaps we'll be able to give you a better suggestion...

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No C drive as I'm *nix/AMP.

    As far as the code...well..that's really it. Other than replacing the echo statement with a new var
    $MyFile = $file;
    And printing $MyFile in the url() of a css background-image.

    I struggled with the var in the CSS for a while cuz $file was not available outside the if statement. When I put it into the new var $MyFile the page loaded, once.

    My first thought was there is some special order in the behaviour of the browser loading the various bits (PHP, xHTML, CSS, images).

    The goal is simple. I'm testing some images on a xHTML page. Rather then change my xHTML every time, I worked out this scriptie to get the file name and paste it into the CSS. Then I put the image in the background of the body and stuck a link to another page in a div set 100%. The background is clickable to the next page and vice-versa. Then I can compare the images without having to rewrite the code.

    I could find another way to do this with JavaScript, but I'm learn'n PHP and (better) CSS. The friggn source shows the code changed and the cache is turned off in Moz. I'm stumped.
    Dinopad R40 - F15/XP
    APACHE 2
    MYSQL 5
    PHP 5

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,157
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    When you say "worked once" do you mean it works every "first time" (i.e. intial page load but not after clicked) or it only worked the first time you tried the new modified code?

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    I'd still like to see said modified code...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •