Jump to content

Archived

This topic is now archived and is closed to further replies.

Twentyoneth

open/readdir is giving me trouble...

Recommended Posts

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:
[code]<?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);

               ?>[/code]

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.