Q:

download fwrite($file, $data1); to excel sheet

i am having a page that shows all database with filter functionality..and after filter i want to download in to excel formate...i am sucessfull to fetch all the data and fwrite() it..now please explain me how to download it to excel sheet 
http://sms.weddingsplanner.co.in/all_inquiry.php ths is my page on which excell button appear..
      <?php 
                include 'functions.php';
              ob_start();

     if($_POST['types'] == 'name') {  

          $query = "SELECT * FROM visitor_detail WHERE name='".$_POST['filter']."'                               ORDER BY id     DESC ";  
  }  
                         elseif($_POST['types'] == 'mobile') {  

            $query = "SELECT * FROM visitor_detail WHERE mobile='".$_POST['filter']."' ORDER BY id   DESC ";  
       } 
              elseif($_POST['types'] == 'OccasionType') {  

    $query = "SELECT * FROM visitor_detail WHERE OccasionType='".$_POST['filter']."' ORDER BY id DESC ";  
            } 

       elseif($_POST['types'] == 'InquiryDate') {  
    $query="SELECT * FROM visitor_detail WHERE TodayDate between '".$_POST['From']."' and   '".$_POST['TO']."' ORDER BY id DESC " ;  
     }

    elseif($_REQUEST['types'] == 'OccasionDate') {  
                     $que="SELECT * FROM visitor_detail WHERE date between      '".$_REQUEST['From']."' and '".$_REQUEST['To']."' ORDER BY id DESC ";  
                    }
    else {  
                 $query = "SELECT * FROM visitor_detail ORDER BY id DESC ";  
            } 

  $sql = mysql_query($query); 

               $line1="Id\tgender\tname\tmobile\taddress\temail\totherno\tzipcode\tOccasionType\tdate\tgue      st\tdescription\tTodayDate\tauther\t";
             $data="$line1\n";
           $br = '<br>';

         $fileName = "./my.txt";
 $file = fopen($fileName, "w");
fwrite($file, $data."\n");
        $i=1;  
  while($row = mysql_fetch_assoc($sql))
{
            $line2=$i . "\t" . $row['gender'] . "\t" . $row['name'] . "\t" .                           $row['mobile'] . "\t" .    $row['address'] . "\t" . $row['email'] . "\t" . $row['otherno']  . "\t" .     $row['zipcode'] .    "\t" . $row['OccasionType'] . "\t" . $row['date'] . "\t"                              . $row['guest'] . "\t" .    $row['description'] . "\t" . $row['TodayDate'] . "\t" . $row['auther'] . "\t";
      $data1=$line2.$br;
         echo $data1;
              fwrite($file, $data1);
                $i++;
   }
                fclose($file);

  ?>

A:

to brute force all csv's on your server to download you could add this to your .htaccess file:
AddType application/octet-stream pdf

EDIT (an inline solution within your php file would be more like this):
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename=example.pdf');
header('Pragma: no-cache');
readfile("/path/to/yourfile.pdf");

