I have MySQL table with LONGBLOB column to save file (although I know saving files directly in database is not a good practice.) Saving works fine! concluding (C:\ProgramData\MySQL\MySQL Server 5.7\Data\dogsport) size of dogsport has increased to the new file saved.
I have written download script part. File downloads to the computer fine (not displaying image in the webpage).
Problem: Downloaded file shows only 4 bytes although it should be 4.83 MB. When I open the image, image is not shown also (see screenshot)
What is the reason?
Updated code for @Andrew:
$query = "SELECT Id,Name,Type,SizeMB FROM Upload"; // Good practice. Do not process much data here. leave Content field
$result = mysqli_query ( $con, $query) or die ("Couldn't execute SELECT query: ". mysqli_error($con));
$nrows = mysqli_num_rows($result);
echo '<table>
<tr>
<td>Id</td>
<td>Name</td>
<td>Type</td>
<td>Size (MB)</td>
</tr>';
$selfpg = $_SERVER['PHP_SELF'];
while( $row = mysqli_fetch_assoc($result) ){
extract($row);
echo "<tr>
<td>$Id</td>
<td>$Name</td>
<td>$Type</td>
<td>$SizeMB</td>
<td> <a href='$selfpg?id=$Id'> Download </a> </td>
</tr>";
}
echo '</table>';
//----------------------------------------------------------------------
if ( isset($_GET['id']) ){
$result_id = "SELECT Content FROM Upload WHERE Id=". $_GET['id'];
$row = mysqli_fetch_assoc($result_id);
extract($row);
$size_bytes = $SizeMB * 1024 * 1024;
header("Content-Type: ". $Type);
header("Content-Length: ". $size_bytes);
header("Content-Disposition: attachment; filename= ". $Name);
echo $Content;
}
else{
echo "<br>No id received to download a file</br>";
}
Still there is the problem
UPDATE !!! - Please download my code with SQL
http://s000.tinyupload.com/index.php?file_id=88155436688298142745