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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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>"); } ?> |
|
|||
|
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>"); > } > ?> > |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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. > |