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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheHippyCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.