Re: Still Racking My Brain
| From: | Richard Davey | Date: | Tue, 30 Dec 2003 15:42:22 +0000 |
| Subject: | Re: Still Racking My Brain | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-173486@lists.php.net to get a copy of this message | ||
Hello stiano,
Tuesday, December 30, 2003, 3:24:04 PM, you wrote:
son> Okay, I got my pathname straightened out, but I'm still showing the
son> "unexpected $" message.
The following works fine for me (on a Windows XP box + PHP4 + Apache)
<?
$dirName = "D:\Graphics";
if (is_dir($dirName) == TRUE)
{
$dp = opendir($dirName);
chdir($dirName);
}
else
{
echo "Not a valid directory";
exit;
}
//add all files in directory to $theFiles array
while ($currentFile !== FALSE)
{
$currentFile = readDir($dp);
$theFiles[] = $currentFile;
}
//extract gif and jpg images
$imageFiles = preg_grep("/jpg$|gif$/", $theFiles);
$output = "
<html>
<head>
<title>Image List</title>
</head>
<body>
<p>
Images in: $dirName
</p>
";
foreach ($imageFiles as $currentFile)
{
$output .= "<a href=\"$currentFile\"><img
src=\"$currentFile\" height=50 width=50></a>\n";
}
$output .= "
</body>
</html>";
$fp = fopen("imageIndex.html", "w");
fputs ($fp, $output);
fclose($fp);
// The following works, except that all the image links are broken because the directory is
wrong
readFile("$dirName\imageIndex.html");
?>
--
Best regards,
Richard mailto:rich@launchcode.co.uk