Re: creating a file to be downloaded by user
| From: | Amanda McComb | Date: | Thu, 22 May 2003 16:01:43 +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-148571@lists.php.net to get a copy of this message | ||
I removed white space from database.php and no longer have errors, but it
still isn't doing what I expected. I expected that a file would be
created, and I can't seem to find the file.
I'm confused on how to export or download a file in PHP. Are there any
good examples that explain how to do this?
On Thu, 22 May 2003, 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 range
> entered.</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.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>