Re: creating a file to be downloaded by user
| From: | Marek Kilimajer | Date: | Thu, 22 May 2003 15:55:33 +0000 |
| Subject: | Re: creating a file to be downloaded by user | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148567@lists.php.net to get a copy of this message | ||
You output something at line 2 of database.php (echo, white character outside of <?php ?>, ... ). First time you output anything, headers are sent and then the output starts, so you cannot add more headers. Simply remove the output from database.php.
Amanda McComb wrote:
I am trying to create a file for a user to download. I am having trouble and I am getting an error about headers (which I admit I don't really understand). Here is the error I get: Warning: Cannot add header information - headers already sent by (output started at /usr/local/packages/apache-1.3.27/htdocs/amccomb/prodev/database.php:2) in /usr/local/packages/apache-1.3.27/htdocs/amccomb/prodev/download.php on line 41 Warning: Cannot add header information - headers already sent by (output started at /usr/local/packages/apache-1.3.27/htdocs/amccomb/prodev/database.php:2) in /usr/local/packages/apache-1.3.27/htdocs/amccomb/prodev/download.php on line 42 Warning: Cannot add header information - headers already sent by (output started at /usr/local/packages/apache-1.3.27/htdocs/amccomb/prodev/database.php:2) in /usr/local/packages/apache-1.3.27/htdocs/amccomb/prodev/download.php on line 43 Warning: Cannot add header information - headers already sent by (output started at /usr/local/packages/apache-1.3.27/htdocs/amccomb/prodev/database.php:2) in /usr/local/packages/apache-1.3.27/htdocs/amccomb/prodev/download.php on line 44 Warning: Cannot add header information - headers already sent by (output started at /usr/local/packages/apache-1.3.27/htdocs/amccomb/prodev/database.php:2) in /usr/local/packages/apache-1.3.27/htdocs/amccomb/prodev/download.php on line 45 First Name Last Name test test test test test test test test test test test test dfg dfgffhf dfg dfgffhf dfg dfgffhf And here is my code: <? include("database.php"); if ($start_date and $end_date){$count_query = "SELECT count(*) FROM customer_t"; $count_query .= " WHERE date_entered BETWEEN '"; $count_query .= $start_date; $count_query .= "' and '"; $count_query .= $end_date; $count_query .= "' ORDER BY date_entered";$num_results = mysql_query($count_query) or die("Customer Count Failed!");$num_result = mysql_fetch_array($num_results);if ($num_result[0]== 0){ ?><font color=red>No Results for the date rangeentered.</font><?}else{$sql = "SELECT first_name, last_name FROM customer_t "; $sql .= "WHERE date_entered BETWEEN '$start_date' and'$end_date'"; $query = mysql_query($sql);if (!$query) {echo('Error'); } else { $content = "First Name\tLast Name\n"; while (list($first_name, $last_name)=mysql_fetch_row($query)) { $content = $content."$first_name\t$last_name\n"; } } header("Content-type: application/vnd.ms-excel"); header("Content-disposition: inline; filename=test_schedule.xls"); header("Content-Length: " . strlen($content)); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: public"); echo("$content"); } } ?> What am I doing wrong? Is there a better way to allow a user to download a file? Thanks.