Downloaded file not opening in correct format
<p>I have two php files<br>
 1. List_files ->show all uploaded files<br>
 2. Get_file ->to download files from listed files...</p>

<p>Now when i download any image or any text document and try to open it it is not getting opened,</p>

<p>Error is format not supported everytime.</p>

<p>My image is .jpeg </p>

<p>I am using Windows Vista with Firefox.<br>
No problem in downloading, problem is in opening the file..</p>

<pre><code>get_file.php

&lt;?php
                                                                        // Make sure an ID was passed
    if(isset($_GET['id'])) 
    {
                                                                      // Get the ID
        $id = intval($_GET['id']);

                                                                   // Make sure the ID is in fact a valid ID
        if($id &lt;= 0)  
        {
            die('The ID is invalid!');
        }
       else 
        {
                                                              // Connect to the database
           $con=mysql_connect("localhost","root","");

                if(!$con)
                {
                    die('Could Not Connect:'.mysql_error());
                }    

                mysql_select_db("tcs",$con);

                                                                                                        // Fetch the file information
           $query = "SELECT `mime`, `name`, `size`, `data` FROM `file` WHERE `id` = {$id}";
           $result=mysql_query($query,$con);

           if($result) 
           {

                $count = mysql_num_rows($result);                                                           // Make sure the result is valid
                if($count == 1) 
                {
                                                                                        // Get the row
                   $row = mysql_fetch_array($result);


                    // Print headers

                   header("Content-Type: ".$row['mime']);
                   header("Content-Length: ".$row['size']);
                   header("Content-Disposition: attachment; filename=".$row['name']);

                   // Print data
                   echo $row['data'];
               }
               else 
               {
                   echo 'Error! No image exists with that ID.';
               }

               // Free the mysqli resources
               //mysql_free_result($result);
           }
           else 
           {
               echo "Error! Query failed: &lt;pre&gt;".mysql_error()."&lt;/pre&gt;";
           }
           mysql_close();
       }
   }
   else 
   {
       echo 'Error! No ID was passed.';
   }
   ?&gt;
</code></pre>
