Jump to content


Photo

open/readdir is giving me trouble...


  • Please log in to reply
1 reply to this topic

#1 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 10 April 2006 - 10:29 PM

I have a directory called 'upcoming' in which you would put an event that might be coming up, well if that event falls on the current date, I would like to display a different color in the title of something.

This is what I have:
<?php

               $dir = 'upcoming/';
               $date = date(Ymd);

               $handle = opendir($dir);
               $file = readdir($handle);

               if($file !== '.' && $file !== '..') {
                  $blue = substr($file, 0, 8);
                  if ($blue = $date) {
                      echo "               <table border='0' cellspacing='0' cellpadding='0' width='505' style='border-style: solid; border-left-width: 1px; border-right-width: 0px; border-top-width: 0px; border-bottom-width: 1px; border-color: #000000;'><tr><td vAlign='top'>
                  <img src='images/cspacerblue.png' width='100%' height='13' vAlign='top'></img>
               </td><td width='13' height='13'>
                  <img src='images/ccornerblue.png' width='13' height='13'></img>
               </td></tr><tr><td align='center' vAlign='top' class='content'>";
                     } else {
                      echo "               <table border='0' cellspacing='0' cellpadding='0' width='505' style='border-style: solid; border-left-width: 1px; border-right-width: 0px; border-top-width: 0px; border-bottom-width: 1px; border-color: #000000;'><tr><td vAlign='top'>
                  <img src='images/cspacer.png' width='100%' height='13' vAlign='top'></img>
               </td><td width='13' height='13'>
                  <img src='images/ccorner.png' width='13' height='13'></img>
               </td></tr><tr><td align='center' vAlign='top' class='content'>";
                     }
                  }
               closedir($dir);

               ?>

My code currently doesnt work, which is why I am posting. It wont read any files from the directory, the only file it will read is '..', I have echo'd everything out, and '..' is the only file that it will detect. I have ch modded the directory to 777 and that didnt help. Any help from here?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 10 April 2006 - 11:45 PM

The reason you're only getting the file ".." is that you're only reading in one file entry. You need to put in a "while" loop to get all the files. Look at the examples in the manual for the function [a href=\"http://www.php.net/readdir\" target=\"_blank\"]readdir[/a](). These show how to do it.

Another problem is in your "if" statement. You are using a single "=", which is not the comparision operator, that is the "==".

I would also recommend you look at the glob() function, since it is much easier to use than the opendir/readdir functions.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users