baseman101
Baseband Member
- Messages
- 26
- Location
- Purcellville, Virginia
I'm trying to make a file viewer in PHP, but I've run across a problem. It's worked when I used goto;, but I'm not using it because it only works in the later PHP versions. I settled on a function. Basically, the problem is that the $postpath variable doesn't work correctly. It gets defined as nothing. I don't know how this is happening, since I have isset(). Can you help?
PHP:
<?php
echo "<html>\n";
echo "<head>\n";
echo "<title>File Viewer</title>\n";
echo "</head>\n";
echo "<body>\n";
function files()
{
if (isset($postpath) === false) {
$postpath = ".";
global $postpath;
}
global $postpath;
$path = $postpath;
$dir_handle = @opendir($path) or die("Could not open file $path");
echo "<form action=\"#\" method=\"post\">\n";
echo "Directory: " . $path . "<br />\n";
while ($file = readdir($dir_handle)) {
if ($file == ".")
continue;
echo "<input type=\"radio\" name=\"filename\" value=\"$path/$file\">$file<br />\n";
}
echo "<input type=\"submit\" value=\"Go\">\n";
echo "</form>\n";
echo "</body>\n";
echo "</html>";
closedir($dir_handle);
}
if ($_POST) {
if (is_dir($_POST['filename'])) {
$postpath = $_POST['filename'];
files();
exit;
}
$src = $_POST['filename'];
show_source($src);
echo "</body>\n";
echo "</html>";
exit;
}
files();
?>
Last edited: