Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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: View Files

$Dir = "files"; $DirEntries = scandir($Dir); echo "

"; echo " "; echo ""; echo ""; echo ""; echo ""; echo ""; echo " "; foreach ($DirEntries as $Entry) { if ((strcmp($Entry, '.') != 0) && (strcmp($Entry, '..') != 0)) { $FullEntryName=$Dir . "/" . $Entry; echo " "; } } echo "
Directory listing for " . htmlentities($Dir) . "
NameOwner IDPermissions Size
"; 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 ""; echo "
";

?> .

FileUploader.php: File Uploader

$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']) . "\".
"; } }

?>


File to upload:

(25,000 byte limit)

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; ?>

File Download Error

There was an error downloading ""

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

Students also viewed these Databases questions

Question

5. Have you stressed the topics relevance to your audience?

Answered: 1 week ago