0

Code for downloading files in database seems to be not working because file downloaded are corrupted or damage.

This the code I used

if (isset($_GET['id'])) 
{
    $id = $_GET['id'];
    $query = "SELECT * FROM tbl_uploads WHERE fileid = '$id'";
    $result = mysqli_query($connection,$query) or die('Error, query failed');
    list($id, $file, $type, $size, $content) = mysqli_fetch_array($result);
    header("Content-length: $size");
    header("Content-type: $type");
    header("Content-Disposition: attachment; filename=".basename($file)."");
    ob_clean(); 
    flush();            
    $content = stripslashes($content);
    echo $content;
}
  • Watch out! Your code is vulnerable to SQL injection. For more information check [What is SQL injection](https://stackoverflow.com/questions/332365/how-does-the-sql-injection-from-the-bobby-tables-xkcd-comic-work) and [How to prevent](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Mathias May 03 '19 at 04:43
  • @Mathias Noted, thanks. – Dexmel Mico Hernandez May 03 '19 at 05:59

0 Answers0