I need to download a document from the base of the database, it is a pdf, but it is downloaded to me blank, can someone tell me what my code fails?
The sql is correct ....
$id = $_GET['id'];
$sql = "SELECT * FROM documents WHERE id='".$id."'";
$conect = new PDO("mysql:host=localhost;dbname=dbpruebas","root", "", array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$resultado = $conect->query($sql);
if (isset($resultado)) {
$fila = $resultado->fetch();
if ($fila !== false) {
$ruta = "./files/" . $fila['filepath'];
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename=' . $fila['name'] . ".pdf" );
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($ruta) );
readfile($ruta);
}
}