Adding additional strpos definition

I am not a programmer by any means. I mainly just edit code for our website the best I can, and its usually a hack job at that. I am in need of some assistance. The web programmer that was here got fired and we are trying to find a new one so I am left to do the best I can.

We have this php function that lists the contents of a directory as links by a extension. However they want to add files other then PDF's, such as .jpg, to the folder and have them show up as well. I cannot figure it out.

If anyone could help me out it would be greatly appreciated, below is the code I am referencing.
?php
 
 
$dir = "labels/"; // Directory where files are stored
 
 
if ($dir_list = opendir($dir))
{
while(($filename = readdir($dir_list)) !== false)
{
if(strpos($filename,'.pdf')>0)
{
?>
<style type="text/css">
<!--
a {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	color: #CC0000;
}
a:hover {
	color: #CC0000;
}
-->
</style>
<p><a href="<?php echo $dir, $filename; ?>"><?php echo $filename;?></a></p>
<p>
  <?php
}
}
closedir($dir_list);
}
 
?>
</p>

Open in new window

lipariAsked:
Who is Participating?
 
TheHippyConnect With a Mentor Commented:
you could replace this line

if(strpos($filename,'.pdf')>0)

with

if(strpos($filename,'.pdf')>"0" || strpos($filename,'.jpg')>"0")

This is saying if $filename contains .pdf OR $filename contains .jpg continue

Hope this helps

Danny
0
 
lipariAuthor Commented:
That did help! It worked perfectly! Thank you! If they dont hire someone soon I will need to take some classes I guess lol.
0
 
lipariAuthor Commented:
wait. it worked for firefox but not IE. In IE it just keeps trying to load the page over and over and over.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
TheHippyCommented:
can you paste the updated piece of code please buddy?
0
 
lipariAuthor Commented:
i apologize, here you go. Here is the whole page just not the part i pasted earlier.
<title>Website - Customer Label Printing</title>

<?PHP include('header.inc'); ?>
<center>
<br>
<br>
<font size="+2"<i>Item Nutritional Information
<center><br>
<?php
 
 
$dir = "labels/"; // Directory where files are stored
 
 
if ($dir_list = opendir($dir))
{
while(($filename = readdir($dir_list)) !== false)
{
if(strpos($filename,'.jpg')>"0" || strpos($filename,'.zpl')>"0"|| strpos($filename,'.ZPL')>"0") || strpos($filename,'.JPG')>"0")
{
?>
<style type="text/css">
<!--
a {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	color: #CC0000;
}
a:hover {
	color: #CC0000;
}
-->
</style>
<p><a href="<?php echo $dir, $filename; ?>"><?php echo $filename;?></a></p>
<p>
  <?php
}
}
closedir($dir_list);
}
 
?>
</p>

<?PHP include('footer.inc'); ?>

Open in new window

0
 
lipariAuthor Commented:
i apologize again. i pasted from the wrong page where there were errors. Here is the correct code but still same problem. works in firefox but not IE.
<title>Website - Customer Label Printing</title>

<?PHP include('header.inc'); ?>
<center>
<br>
<br>
<font size="+2"<i>Item Nutritional Information
<center><br>
<?php
 
 
$dir = "labels/"; // Directory where files are stored
 
 
if ($dir_list = opendir($dir))
{
while(($filename = readdir($dir_list)) !== false)
{
if(strpos($filename,'.jpg')>"0" || strpos($filename,'.zpl')>"0" || strpos($filename,'.ZPL')>"0" || strpos($filename,'.JPG')>"0"  || strpos($filename,'.pdf')>"0")
{
?>
<style type="text/css">
<!--
a {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	color: #CC0000;
}
a:hover {
	color: #CC0000;
}
-->
</style>
<p><a href="<?php echo $dir, $filename; ?>"><?php echo $filename;?></a></p>
<p>
  <?php
}
}
closedir($dir_list);
}
 
?>
</p>

<?PHP include('footer.inc'); ?>

Open in new window

0
 
TheHippyCommented:
use this.. it's more efficiant :-)

$filearray      =      array('jpg','zpl','pdf');
$dir = "labels/"; // Directory where files are stored

if ($dir_list = opendir($dir)) {
      while($file=readdir($dir_list)){
            $ext = substr($file, strrpos($file, '.') + 1);
            if(in_array($ext,$filearray)) {
                  print("<p><a href=" . $dir . $file . ">" . $file . "</a></p>");
            }
      }
}
0
 
lipariAuthor Commented:
Thank you very much :)
0
 
lipariAuthor Commented:
I also found taking out the style sheet helped as well. Have a good one!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.