I am a beginner to PHP so please forgive any ignorance…
I am using the exec() command as following to get the list of files in my media directory..
<?php // exec.php
$cmd = "dir"; // Windows
exec(escapeshellcmd($cmd), $output, $status);
if ($status) echo "Exec command failed";
else
{
echo "<pre>";
foreach($output as $line) echo "<a href='$line'>$line</a> \n";
}
?>
The problem is it gives the list of files along with the various timestamps of the filenames-
Volume in drive F is Movies
Volume Serial Number is 172B-1DE0
06/17/2011 01:11 AM 6,318 bck.gif
Hence, here it creates clickable link to each line for the output which needless to say does not work.
What I want is that it will only create clickable links for the filenames and not the extra meta information, which the user can then click to launch his native program like this-
video1.mpg
video2.mpg
bck.gif
There is no need to use
exec();to list files in the directory, PHP has many build in functions for dealing with the file system:From the
readdir()manual page: