Hello guys, i do not have very good PHP knowledge so go easy on me
So I am building this site, where users can create files (for now only text files)
Creating file is done and works, now I want to add function to download the file, my code so far
<?php
error_reporting(E_ALL);
$file = $_GET['file'];
if(file_exists('users/'.$_COOKIE['username'].'/files'. '/' .$file)) {
header('Content-Type: text/plain');
$content = file_get_contents('users/' . $_COOKIE['username'] . '/files' . '/' .$file);
//var_dump($content);
//die();
header('Content-Disposition: attachment; filename="'.$file.'"');
readfile($file);
} else {
echo "File does not exists!";
}
?>
I have 5 files 1.txt 2.txt 3.txt ... 5.txt. Download part works alright, but the file downloaded is blank If i var_dump the file i get the following : string(4) "Five" for the 5.txt and string(3) "Two" for the 2.txt
I know that the code is awful to look but I am not that experienced in coding. Am I missing some headers?