is_dir and is_file() work on one server but not another

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ravenslay3r@gmail.com

    #1

    is_dir and is_file() work on one server but not another

    I'm using a script to grab images from a directory and put them to the
    screen, but i want it to ignore sub-directories like CVS/ . Adding the
    tag "&& !is_dir($file)" to the correct conditional statement solved it
    on my test server, but not on the actual site.

    How is this possible? How can I fix it?


    thanks,

    RavenSlay3r



    Working open-test site on Dreamhost.com servers (PHP 5.0 now i think)


    Broken Mainsite running on BlueGravity.com servers (PHP 4 & 5)
    http://lcpaver.com/index.php?colors_...s&paver_colors



    Here's the script:
    <?php
    $image_dir = "images/colors/classic";
    $dir_ptr = opendir("$image _dir/");




    # grab images and put in an array
    while ($file = readdir($dir_pt r)) {
    $content[] = $file;
    }
    closedir($dir_p tr);
    sort($content);




    # output list of files found to page source for testing purpose
    echo ("<!-- Files in " . $image_dir . " :\n");
    foreach ($content as $file) {
    echo ($file . "\n");
    }
    echo ("-->\n");




    # Create new array with images only
    $cnt=0;
    foreach ($content as $image) {
    if ( $image != "." && $image != ".." &&
    !is_dir($image) ) {
    # gets size of $image
    $img_info = getimagesize("$ image_dir/$image");
    // $img_info = $img_info[3];
    $img_info = "style=\"width: 120px;
    height:80px;\"" ;
    $img_name = str_replace ("_", " ", $image);
    $img_name = str_replace (".jpg", "",
    $img_name);
    # display $image
    echo ("<div class=\"onecolo r\">");
    echo ("<div class=\"imgshad ow\"
    style=\"float: left;\">\n");
    echo ("<img src=\"$image_di r/$image\"
    alt=\"$img_name \"
    $img_info>\n");
    echo ("</div>\n");
    echo ("<p>$img_na me</p>");
    echo ("</div>\n");
    $cnt++;
    }
    }
    $maxItems = $cnt-1;


    # output number of files found to page source for testing
    purpose echo ("<!-- " . $maxItems . " images found -->\n");


    if ($maxItems = 0) {
    echo ("<h1>There are no images in this library</h1>");
    }
    ?>

  • Dave

    #2
    Re: is_dir and is_file() work on one server but not another

    Hi Raven
    I just got an email from dreamhost support (I only sent it about twenty
    minutes ago - great support) They didn't
    actually upgrade to php 5, they upgraded to 4.3.10, the email announcment
    they sent was misleading I believe. I thought they were upgrading to php5
    too.

    php5 from your actual site might break scripts, this does not happen on
    dreamhost as php4 is still there.

    <ravenslay3r@gm ail.com> wrote in message
    news:1103478503 .760881.309480@ z14g2000cwz.goo glegroups.com.. .[color=blue]
    > I'm using a script to grab images from a directory and put them to the
    > screen, but i want it to ignore sub-directories like CVS/ . Adding the
    > tag "&& !is_dir($file)" to the correct conditional statement solved it
    > on my test server, but not on the actual site.
    >
    > How is this possible? How can I fix it?
    >
    >
    > thanks,
    >
    > RavenSlay3r
    >
    >
    >
    > Working open-test site on Dreamhost.com servers (PHP 5.0 now i think)
    >[/color]
    http://guardiansrealm.net/lcpaver/in...s&paver_colors[color=blue]
    >
    > Broken Mainsite running on BlueGravity.com servers (PHP 4 & 5)
    > http://lcpaver.com/index.php?colors_...s&paver_colors
    >
    >
    >
    > Here's the script:
    > <?php
    > $image_dir = "images/colors/classic";
    > $dir_ptr = opendir("$image _dir/");
    >
    >
    >
    >
    > # grab images and put in an array
    > while ($file = readdir($dir_pt r)) {
    > $content[] = $file;
    > }
    > closedir($dir_p tr);
    > sort($content);
    >
    >
    >
    >
    > # output list of files found to page source for testing purpose
    > echo ("<!-- Files in " . $image_dir . " :\n");
    > foreach ($content as $file) {
    > echo ($file . "\n");
    > }
    > echo ("-->\n");
    >
    >
    >
    >
    > # Create new array with images only
    > $cnt=0;
    > foreach ($content as $image) {
    > if ( $image != "." && $image != ".." &&
    > !is_dir($image) ) {
    > # gets size of $image
    > $img_info = getimagesize("$ image_dir/$image");
    > // $img_info = $img_info[3];
    > $img_info = "style=\"width: 120px;
    > height:80px;\"" ;
    > $img_name = str_replace ("_", " ", $image);
    > $img_name = str_replace (".jpg", "",
    > $img_name);
    > # display $image
    > echo ("<div class=\"onecolo r\">");
    > echo ("<div class=\"imgshad ow\"
    > style=\"float: left;\">\n");
    > echo ("<img src=\"$image_di r/$image\"
    > alt=\"$img_name \"
    > $img_info>\n");
    > echo ("</div>\n");
    > echo ("<p>$img_na me</p>");
    > echo ("</div>\n");
    > $cnt++;
    > }
    > }
    > $maxItems = $cnt-1;
    >
    >
    > # output number of files found to page source for testing
    > purpose echo ("<!-- " . $maxItems . " images found -->\n");
    >
    >
    > if ($maxItems = 0) {
    > echo ("<h1>There are no images in this library</h1>");
    > }
    > ?>
    >[/color]


    Comment

    • Andy Hassall

      #3
      Re: is_dir and is_file() work on one server but not another

      On 19 Dec 2004 09:48:23 -0800, ravenslay3r@gma il.com wrote:
      [color=blue]
      >I'm using a script to grab images from a directory and put them to the
      >screen, but i want it to ignore sub-directories like CVS/ . Adding the
      >tag "&& !is_dir($file)" to the correct conditional statement solved it
      >on my test server, but not on the actual site.
      >
      >How is this possible? How can I fix it?[/color]

      My initial impression is to check the following bits:
      [color=blue]
      >$image_dir = "images/colors/classic";
      >$dir_ptr = opendir("$image _dir/");[/color]

      OK, you're opening up a given directory, relative to the current directory.
      Current working directory may not be the same between the two?
      [color=blue]
      ># grab images and put in an array
      >while ($file = readdir($dir_pt r)) {
      >$content[] = $file;
      >}
      >closedir($dir_ ptr);
      >sort($content) ;[/color]

      [color=blue]
      ># Create new array with images only
      >$cnt=0;
      >foreach ($content as $image) {
      >if ( $image != "." && $image != ".." &&
      >!is_dir($image )) {[/color]

      Aren't you missing "$image_dir/" as a prefix for the is_dir() call? You've
      correctly got it in the getimagesize() call below.
      [color=blue]
      ># gets size of $image
      >$img_info = getimagesize("$ image_dir/$image");[/color]

      --
      Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
      <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

      Comment

      • ravenslay3r@gmail.com

        #4
        Re: is_dir and is_file() work on one server but not another

        Very intresting but good to know about Dreamhost. That means MY
        web-site will still work! I was afraid to look... :-P Do you use them
        also? They have been great to me!

        I wouldn't expect PHP5 to be breaking on is_dir() but i'm not ruling
        out the possiblilty yet.

        Comment

        • ravenslay3r@gmail.com

          #5
          Re: is_dir and is_file() work on one server but not another

          Goodpoint. Alot of this was existing code I inherited from another
          web-designer and i'm just adding to/maintaining it... <sigh>

          I thought the fullpathname was included in $image, but perhaps not.
          I'll give this a try!

          Thanks,
          Raven

          Comment

          • Dave

            #6
            Re: is_dir and is_file() work on one server but not another

            Hi Yes
            I use them aswell , they are great in everyway particullarly support.
            However I have been told that they are overselling and thus sites with them
            are slow. My site never seemed slow to me, although I have seen faster.

            I'm actually only new to php, but have heard that as well as functions which
            wont work in version 4 because they from 5, it is also true of the reverse.

            The guy from dreamhost said that it will be a while until 5 is instailled,
            he said they'd probabely wait until it is packaged with debian (which makes
            sense) as it would break nearly everyone's scripts.


            <ravenslay3r@gm ail.com> wrote in message
            news:1103488033 .269574.163760@ f14g2000cwb.goo glegroups.com.. .[color=blue]
            > Very intresting but good to know about Dreamhost. That means MY
            > web-site will still work! I was afraid to look... :-P Do you use them
            > also? They have been great to me!
            >
            > I wouldn't expect PHP5 to be breaking on is_dir() but i'm not ruling
            > out the possiblilty yet.
            >[/color]


            Comment

            Working...