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

This is a discussion on is_dir and is_file() work on one server but not another within the PHP Language forums, part of the PHP Programming Forums category; I'm using a script to grab images from a directory and put them to the screen, but i want ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-19-2004
ravenslay3r@gmail.com
 
Posts: n/a
Default 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)
http://guardiansrealm.net/lcpaver/in...s&paver_colors

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_ptr)) {
$content[] = $file;
}
closedir($dir_ptr);
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=\"onecolor\">");
echo ("<div class=\"imgshadow\"
style=\"float: left;\">\n");
echo ("<img src=\"$image_dir/$image\"
alt=\"$img_name\"
$img_info>\n");
echo ("</div>\n");
echo ("<p>$img_name</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>");
}
?>

Reply With Quote
  #2 (permalink)  
Old 12-19-2004
Dave
 
Posts: n/a
Default 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@gmail.com> wrote in message
news:1103478503.760881.309480@z14g2000cwz.googlegr oups.com...
> 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)
>

http://guardiansrealm.net/lcpaver/in...s&paver_colors
>
> 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_ptr)) {
> $content[] = $file;
> }
> closedir($dir_ptr);
> 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=\"onecolor\">");
> echo ("<div class=\"imgshadow\"
> style=\"float: left;\">\n");
> echo ("<img src=\"$image_dir/$image\"
> alt=\"$img_name\"
> $img_info>\n");
> echo ("</div>\n");
> echo ("<p>$img_name</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>");
> }
> ?>
>



Reply With Quote
  #3 (permalink)  
Old 12-19-2004
Andy Hassall
 
Posts: n/a
Default Re: is_dir and is_file() work on one server but not another

On 19 Dec 2004 09:48:23 -0800, ravenslay3r@gmail.com wrote:

>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?


My initial impression is to check the following bits:

>$image_dir = "images/colors/classic";
>$dir_ptr = opendir("$image_dir/");


OK, you're opening up a given directory, relative to the current directory.
Current working directory may not be the same between the two?

># grab images and put in an array
>while ($file = readdir($dir_ptr)) {
>$content[] = $file;
>}
>closedir($dir_ptr);
>sort($content);



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


Aren't you missing "$image_dir/" as a prefix for the is_dir() call? You've
correctly got it in the getimagesize() call below.

># gets size of $image
>$img_info = getimagesize("$image_dir/$image");


--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Reply With Quote
  #4 (permalink)  
Old 12-19-2004
ravenslay3r@gmail.com
 
Posts: n/a
Default 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.

Reply With Quote
  #5 (permalink)  
Old 12-19-2004
ravenslay3r@gmail.com
 
Posts: n/a
Default 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

Reply With Quote
  #6 (permalink)  
Old 12-19-2004
Dave
 
Posts: n/a
Default 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@gmail.com> wrote in message
news:1103488033.269574.163760@f14g2000cwb.googlegr oups.com...
> 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.
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:20 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0