Link to home
Start Free TrialLog in
Avatar of daleoran
daleoranFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Content of folder and output

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

ASKER CERTIFIED SOLUTION
Avatar of aolXFT
aolXFT

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aolXFT
aolXFT

Not the most efficient way but, It'd do the job.
Avatar of daleoran

ASKER

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