Twentyoneth Posted April 10, 2006 Share Posted April 10, 2006 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 https://forums.phpfreaks.com/topic/7067-openreaddir-is-giving-me-trouble/ Share on other sites More sharing options...
kenrbnsn Posted April 10, 2006 Share Posted April 10, 2006 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 https://forums.phpfreaks.com/topic/7067-openreaddir-is-giving-me-trouble/#findComment-25693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.