Sunday, March 11, 2018

Downloading file using PHP pointer

I am storing files above the root directory of my server, and I'm planning on giving users a download by using a php file.



Here is my code:

For the download link:



Download


and for the FileGrab.php file:



//This will grab a file from the server


if (file_exists(UPLOAD_ADR.$_GET['adr'])) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.CATPart"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header("Content-length: ".filesize(UPLOAD_ADR.$_GET['adr']));

readfile(UPLOAD_ADR.$_GET['adr']);

exit;
}
?>


I got the above code (in essence) from here



FileGrab.php is loading but it looks like it is just spewing out a raw text form of the file, arbitrary text/symbols etc.



Checked that the file exists, and file size returns a value. Don't know how to get anymore errors to check out of it!




Does it make a difference this is a .CATPart file, which is a little abstract but necessary...



Any help greatly appreciated :)

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...