Solved

Content of folder and output

Posted on 2003-12-05
4
241 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
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
aolXFT earned 100 total points
Comment Utility
<?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
Comment Utility
Not the most efficient way but, It'd do the job.
0
 
LVL 10

Author Comment

by:daleoran
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now