Saturday 28 January 2017

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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...