I try to download files uploaded to my server, but after download, they are empty, name and ending are correct, but not the rest. I try downloading it with that script:
<?php
session_start();
$file = basename($_GET['file']);
$path = 'uploads/'.$_SESSION['id']."/".$file;
if(!$path){ // file does not exist
die('file not found');
} else {
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="'.$file.'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($path);
exit;
}
I also tried multiple types of header but it doesn't seem to work.. Files to downnload can be all types, txt-files, pictures, .exe-files, etc.
FYI: When uploading the files they are saved in folders named with the user-id, that's how the path comes about. And the path seems to be completely right.
The file I try to download (as test-file) is a .txt-file, when opening it in the browser (....com/uploads/23/test.txt
) I get the content, so it's not empty.
Does anybody have an idea, what the problem could be?...