Jump to content

open/readdir is giving me trouble...


Twentyoneth

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.