Created
May 20, 2012 18:36
-
-
Save haric/2759071 to your computer and use it in GitHub Desktop.
Download file from DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| ob_start(); | |
| ini_set ("display_errors", 1); | |
| if (isset($_REQUEST["id"])) { | |
| $id = $_REQUEST["id"]; | |
| $c = mysqli_connect("localhost" , "root", "", "mcdb"); | |
| $sql = "SELECT name, type, size, content " ."FROM photo WHERE id = '$id'"; | |
| $rc = mysqli_query($c, $sql) or die('Error, query failed'); | |
| list($name, $type, $size, $content) = mysqli_fetch_array($rc); | |
| // since we are expecting a single row | |
| header("Content-length: $size"); | |
| header("Content-type: $type"); | |
| header("Content-Disposition: attachment; filename=$name"); | |
| echo $content; | |
| mysqli_free_result($rc); | |
| mysqli_close($c); | |
| } | |
| ob_end_flush(); | |
| ini_set ("display_errors", 0); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment