flim_flamini Posted August 24, 2007 Share Posted August 24, 2007 Hi, Can anyone help this newbie out? There is a page on the site I'm working on that has images lined up on the right side of the page. It appears that they are being grabbed by code I haven't come across before. I'd like to be able to change out the pictures and allow my client to change/upload the pics through their admin page. Here is the part of code in question: function file_type($file){ $path_chunks = explode("/", $file); $thefile = $path_chunks[count($path_chunks) - 1]; $dotpos = strrpos($thefile, "."); return strtolower(substr($thefile, $dotpos + 1)); } $path = "award_images/"; $file_types = array('jpeg', 'jpg', 'ico', 'png', 'gif', 'bmp', 'html'); $p = opendir($path); while (false !== ($filename = readdir($p))) { $files[] = $filename; } sort($files); foreach ($files as $file) { $extension = file_type($file); if($file != '.' && $file != '..' && array_search($extension, $file_types)){ $file_count++; echo '<tr><td><img src="'.$path.$file.'"></td></tr>'; } } Here is the entire code: <table border="0" width="100%"> <tr><td> <? $tablename = "********".$header."_sterling"; //echo $tablename; $optyear = mysql_query("SELECT DISTINCT awards_year FROM $tablename ORDER BY awards_year DESC"); while ($myoptyear = mysql_fetch_array($optyear)) { $distyear = $myoptyear["awards_year"]; //echo $distyear."<br>"; ?> <img src="images/bullet2.gif" alt="" width="11" height="11" /> <strong><font face="Arial, Helvetica, sans-serif" size="2"><? echo $distyear; ?></font></strong><br> <? $optsub = mysql_query("SELECT * FROM $tablename WHERE awards_year = '$distyear' ORDER BY awards_name ASC"); while ($myoptsub = mysql_fetch_array($optsub)) { $name = $myoptsub["awards_name"]; $title = $myoptsub["awards_title"]; $url = $myoptsub["awards_link_url"]; $link = $myoptsub["awards_link"]; $year = $myoptsub["awards_year"]; if ($url !='') {$imgcode = "<a href='$url' target='_blank'><u>$link</u></a>"; } else {$imgcode = "";} ?> <font face="Arial, Helvetica, sans-serif" size="2" > <img src="images/bullet4.gif" alt="" width="9" height="11" /> <? echo ucwords($name); ?> <? echo $imgcode; ?><br> <img src="images/spacer.gif" alt="" width="25" height="1" /> <? echo ucwords($title); ?> <br> <? } echo "<br>"; } ?> </font> </td> <td height="100%"> <table height="100%"> <? function file_type($file){ $path_chunks = explode("/", $file); $thefile = $path_chunks[count($path_chunks) - 1]; $dotpos = strrpos($thefile, "."); return strtolower(substr($thefile, $dotpos + 1)); } $path = "award_images/"; $file_types = array('jpeg', 'jpg', 'ico', 'png', 'gif', 'bmp', 'html'); $p = opendir($path); while (false !== ($filename = readdir($p))) { $files[] = $filename; } sort($files); foreach ($files as $file) { $extension = file_type($file); if($file != '.' && $file != '..' && array_search($extension, $file_types)){ $file_count++; echo '<tr><td><img src="'.$path.$file.'"></td></tr>'; } } ?> </table> </td> </tr> </table> <p style='text-align:justify;'> <font face="Arial, Helvetica, sans-serif" size="2" > <br /><img src="images/photo17a.jpg" alt="Photo" hspace="5" vspace="3" width="198" height="141" align="right" /><em>*Finalist</em> <br /><br />Also, in the June 1996 issue of ....</strong></em></font></p><br /><br /> </font> </p> Link to comment https://forums.phpfreaks.com/topic/66529-help-dont-know-how-images-are-being-pulled-w-opendir-readdir/ Share on other sites More sharing options...
flim_flamini Posted August 24, 2007 Author Share Posted August 24, 2007 Thanks in advance for taking a look! Link to comment https://forums.phpfreaks.com/topic/66529-help-dont-know-how-images-are-being-pulled-w-opendir-readdir/#findComment-333169 Share on other sites More sharing options...
MadTechie Posted August 24, 2007 Share Posted August 24, 2007 Erm.. not 100% sure of the "problem".. Link to comment https://forums.phpfreaks.com/topic/66529-help-dont-know-how-images-are-being-pulled-w-opendir-readdir/#findComment-333171 Share on other sites More sharing options...
flim_flamini Posted August 24, 2007 Author Share Posted August 24, 2007 Sorry I wasn't more clear. I don't understand how the code is grabbing the pictures in question, thus I'm not able to change said pictures. Link to comment https://forums.phpfreaks.com/topic/66529-help-dont-know-how-images-are-being-pulled-w-opendir-readdir/#findComment-333268 Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 It sets the directory to $path and gets all the files from that directory. Then it checks to see if the file is an img, if it is, it increments $file_count and echos out the html to show the picture with echo '<tr><td><img src="'.$path.$file.'"></td></tr>';. Link to comment https://forums.phpfreaks.com/topic/66529-help-dont-know-how-images-are-being-pulled-w-opendir-readdir/#findComment-333280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.