php下载和显示图像都不起作用[重复]

This question already has an answer here:

When I display saved image from database, webpage does show only empty square. (see screenshot). Even after downloading it, image does not show and open. (I have published another post in SO for not working downloaded image section.

enter image description here

My code;

            $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;
            /* When displaying the image on the webpage "Content-Type" is enough */
            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>";
        }

UPDATE !!! - Please download my code with SQL http://s000.tinyupload.com/index.php?file_id=88155436688298142745

</div>

As I stated in my comment, you cannot change the headers once you start output.

In the case of displaying the image, you'll want to put the image data right in the src="" attribute of an image tag.

In the case of downloading it, you can output it ( with the correct headers ) into an iframe that is hidden on the page, with the src of the iframe the location of the php script that downloads it.

You can also trigger the download, by appending the iframe to the page with javascript. or by using a form with the target set to the id of the iframe and the action the location of the download script.

Cheers.