daleoran
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Not the most efficient way but, It'd do the job.
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($fil es)); // removing duplicates
echo "<table>"
foreach ($files as $file){
echo "<tr><td>$file.jpg</td><td >$file.pdf </td></tr> \n";
}
echo "</table>";
?>
</BODY>
</HTML>
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($fil
echo "<table>"
foreach ($files as $file){
echo "<tr><td>$file.jpg</td><td
}
echo "</table>";
?>
</BODY>
</HTML>
ASKER
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
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