David,
Yes, there appears to be an error in the download file.
I changed everything to absolute paths and it still does not
work. It will successfully load the list of files into the drop
down, but when I press the button it gives me the download not
available error.
I know this is something simple I am overlooking (beginner
and all), but I just can't figure it out.
Below is the code.
I also trie one version using the jump menu but I can only
get it to read the root folder, such as
www.marketscholar.com/filename. It should be
www.marketscholar.com/PDFs/filename. How can I change the jump menu
code to the PDFs path?
Thanks for the help.
Glenn
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Image drop-down</title>
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<form name="form" id="form">
<p>
<select name="jumpMenu" id="jumpMenu"
onchange="MM_jumpMenu('parent',this,0)">
<option value="">Select an image</option>
<?php
include('Includes/buildFileList5.php');
buildFileList5('PDFs');
?>
</select>
<label></label>
</p>
<p>
<label>Download
<input type="submit" name="Download" id="Download"
value="Submit" />
</label>
</p>
</form>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Image drop-down</title>
</head>
<body>
<form id="form1" name="form1" method="post"
action="download.php">
<p>
<select name="pix" id="pix">
<option value="">Select an image</option>
<?php
include('Includes/buildFileList5.php');
buildFileList5('C:\xampp\htdocs\Garrison\PDFs');
?>
</select>
<label></label>
</p>
<p>
<label>Download
<input type="submit" name="Download" id="Download"
value="Submit" />
</label>
</p>
</form>
</body>
</html>
<?php
function buildFileList5($theFolder) {
// Execute code if the folder can be opened, or fail
silently
if ($contents = @ scandir($theFolder)) {
// initialize an array for matching files
$found = array();
// Create an array of file types
$fileTypes = array('pdf','jpg','jpeg','gif','png');
// Traverse the folder, and add filename to $found array if
type matches
$found = array();
foreach ($contents as $item) {
$fileInfo = pathinfo($item);
if (array_key_exists('extension', $fileInfo) &&
in_array($fileInfo['extension'],$fileTypes)) {
$found[] = $item;
}
}
// Check the $found array is not empty
if ($found) {
// Sort in natural, case-insensitive order, and populate
menu
natcasesort($found);
foreach ($found as $filename) {
echo "<option
value='$filename'>$filename</option>\n";
}
}
}
}
?>
<?php
// block any attempt to explore the filesystem
if (isset($_POST['pix']) && basename($_POST['pix'])
== $_POST['pix']) {
$getfile = $_POST['pix'];
}
else {
$getfile = NULL;
}
// define error handling
$nogo = 'Sorry, download unavailable. <a
href="prompt.php">Back</a>.';
if (!$getfile) {
// go no further if filename not set
echo $nogo;
}
else {
// define the pathname to the file
$filepath = 'C:\xampp\htdocs\Garrison\PDFs'.$getfile;
// check that it exists and is readable
if (file_exists($filepath) &&
is_readable($filepath)) {
// get the file's size and send the appropriate headers
$size = filesize($filepath);
header('Content-Type: application/octet-stream');
header('Content-Length: '.$size);
header('Content-Disposition: attachment;
filename='.$getfile);
header('Content-Transfer-Encoding: binary');
// open the file in binary read-only mode
// suppress error messages if the file can't be opened
$file = @ fopen($filepath, 'rb');
if ($file) {
// stream the file and exit the script when complete
fpassthru($file);
exit;
}
else {
echo $nogo;
}
}
else {
echo $nogo;
}
}
?>