Jump to content

Help. Don't Know how images are being pulled w/ opendir & readdir


flim_flamini

Recommended Posts

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

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
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.