Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Content of folder and output

Posted on 2003-12-05
4
Medium Priority
?
247 Views
Last Modified: 2006-11-17
Hi All
I have a folder that contains for example

picture1.jpg   picture1.pdf
picture2.jpg   picture2.pdf
picture3.jpg   picture3.pdf
etc                etc

is it possible to scan the folder and produce a two column table  - the picture1.jpg displayed in the first cell and a link to the picture1.pdf in the second cell and continuing to insert a row for each additional picture found in the folder. Any help and code to get me started would be greatly appriciated.

Many Thanks in advanced

Michael

0
Comment
Question by:daleoran
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
aolXFT earned 400 total points
ID: 9883611
<?php

$foldername = 'pics';

$dir_h = opendir($foldername);
$files = array();
while( ($filename = readdir($dir_h)) !== false ){
  $files[] = substr($filename, 0, -4); //removing extension.
}

$files = array_flip(array_flip($files)); // removing duplicates

echo "<table>"
foreach($files as $file){
     echo "<tr><td>$file.jpg</td><td>$file.pdf</td></tr>\n";
}
echo "</table>";

?>
0
 
LVL 6

Expert Comment

by:aolXFT
ID: 9883614
Not the most efficient way but, It'd do the job.
0
 
LVL 10

Author Comment

by:daleoran
ID: 9919346
I've put the code in as follows and I am getting the following error message

Parse error: parse error, expecting `','' or `';'' in pics/photo.php on line 22
which is the line
foreach ($files as $file){
I'm just beginning to learn php so I'm a bit stumped with this one

<HTML>
<HEAD>
<TITLE></TITLE>
<META name="description" content="">
<META name="keywords" content="">
<META name="generator" content="CuteHTML">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<?php

$foldername = 'pics';

$dir_h = opendir($foldername);
$files = array();
while( ($filename = readdir($dir_h)) !== false ){
  $files[] = substr($filename, 0, -4); //removing extension.
}

$files = array_flip(array_flip($files)); // removing duplicates

echo "<table>"
foreach ($files as $file){
     echo "<tr><td>$file.jpg</td><td>$file.pdf</td></tr>\n";
}
echo "</table>";

?>


</BODY>
</HTML>
0
 
LVL 10

Author Comment

by:daleoran
ID: 9933863
sorted - there was a ; missing from the first echo.
Just one more thing before I close this question. I've added

while( ($filename = readdir($dir_h)) !== false ) if ($filename !='.' && $filename != '..' && $filename != 'photo.php' && $filename != 'try.php')

to the While to look for the  .  &  ..  and two .php files that are in the folder. How can I use a wildcard to look for any .php file just like u would in dos or windows *.php

Again Many thanks

Michael

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question