Question
Im trying to get my file to download from an directory, but its not prompting an download box. Im using notepad++ and xampp. here are
Im trying to get my file to download from an directory, but its not prompting an download box. Im using notepad++ and xampp. here are my codes. What is wrong here?\Please help with an correct answer.
viewfiles.php:
$Dir = "files"; $DirEntries = scandir($Dir); echo "
Directory listing for " . htmlentities($Dir) . " | |||||
---|---|---|---|---|---|
Name | "; echo "Owner ID | "; echo "Permissions | "; echo "Size | "; echo "||
"; if (is_file($FullEntryName)) echo "" . htmlentities($Entry). ""; else echo htmlentities($Entry); echo " | " . fileowner($FullEntryName); if (is_file($FullEntryName)) { $perms = fileperms($FullEntryName); $perms = decoct($perms % 01000); echo " | 0$perms"; echo " | " . number_format(filesize($FullEntryName), 0) . " bytes"; } else echo " |
?> .
FileUploader.php:
$Dir = "files"; if (isset($_POST['upload'])) { if (isset($_FILES['new_file'])) { if (move_uploaded_file( $_FILES['new_file']['tmp_name'], $Dir . "/" . $_FILES['new_file'] ['name']) == TRUE) { chmod($Dir . "/" . $_FILES['new_file'] ['name'], 0644); echo "File \"" . htmlentities($_FILES['new_file'] ['name']) . "\"successfully uploaded.
"; } else echo "There was an error uploading \"" . htmlentities($_FILES['new_file'] ['name']) . "\".
"; } }
?>
FileDownloader.php:
$Dir = "files"; if (isset($_GET['filename'])) { $FileToGet = $Dir . "/" . stripslashes ($_GET['filename']); if (is_readable($FileToGet)) { } else { $ErrorMsg = "Cannot read \"$FileToGet\""; $ShowErrorPage = TRUE; } } else { $ErrorMsg = "No filename specified"; $ShowErrorPage = TRUE; } if ($ShowErrorPage) { header("Content-Description: File Transfer"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=\"" . $_GET['filename'] . "\""); header("Content-Transfer-Encoding: base64"); header("Content-Length: " . filesize($FileToGet)); readfile($FileToGet); $ShowErrorPage = FALSE; ?>
There was an error downloading ""
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started