[PHP] Sending the results of a query without using a file

2007-05-02 Thread Todd Cary
Some shared servers do not allow the creation of a file, so I am 
looking for a way to take the results of a query (MySQL), create 
a CSV output and have it in a sendable format for the user 
without creating a file.


Many thanks

Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sending the results of a query without using a file

2007-05-02 Thread Kevin Waterson
This one time, at band camp, Todd Cary [EMAIL PROTECTED] wrote:

 Some shared servers do not allow the creation of a file, so I am 
 looking for a way to take the results of a query (MySQL), create 
 a CSV output and have it in a sendable format for the user 
 without creating a file.

sendable to where?

kevin

-- 
Democracy is two wolves and a lamb voting on what to have for lunch. 
Liberty is a well-armed lamb contesting the vote.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sending the results of a query without using a file

2007-05-02 Thread clive

Todd Cary wrote:
Some shared servers do not allow the creation of a file, so I am looking 
for a way to take the results of a query (MySQL), create a CSV output 
and have it in a sendable format for the user without creating a file.




are you sure, then how could you say ftp the files to the server, are 
you not trying to create files in the wrong directory?


hmm if you want to allow the user to download the file, then just send 
the correct headers, using the header() function, for the csv format and 
then echo the contents of the file.


remember your application may spit out some other bits of text and this 
will interfere with sending the headers so you may also need to look at 
the output control functions to clean the outout buffer and then send 
your headers and data:

http://www.php.net/manual/en/ref.outcontrol.php

Regards,

Clive.

{No electrons were harmed in the creation, transmission or reading of 
this email. However, many were excited and some may well have enjoyed 
the experience.}


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sending the results of a query without using a file

2007-05-02 Thread Tijnema !

On 5/2/07, clive [EMAIL PROTECTED] wrote:

Todd Cary wrote:
 Some shared servers do not allow the creation of a file, so I am looking
 for a way to take the results of a query (MySQL), create a CSV output
 and have it in a sendable format for the user without creating a file.


are you sure, then how could you say ftp the files to the server, are
you not trying to create files in the wrong directory?


I have that too on one of my shared hosts, I can't create any files in
my home directory, because the PHP user doesn't have access rights
there, chmodding all directories did fix, (done through SSH). Before i
figured out that I could chmod all directories, I found out that it
does allow me to write in /tmp, and so i stored my files there, but
only temporary of course, because /tmp is cleaned regularly


hmm if you want to allow the user to download the file, then just send
the correct headers, using the header() function, for the csv format and
then echo the contents of the file.


Yep, that's the correct way.


remember your application may spit out some other bits of text and this
will interfere with sending the headers so you may also need to look at
the output control functions to clean the outout buffer and then send
your headers and data:
http://www.php.net/manual/en/ref.outcontrol.php

Regards,

Clive.


I don't think that you will need output buffering, most functions
allow you (or only) return values.

Tijnema








--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sending the results of a query without using a file

2007-05-02 Thread Richard Lynch
On Wed, May 2, 2007 2:17 am, Todd Cary wrote:
 Some shared servers do not allow the creation of a file, so I am
 looking for a way to take the results of a query (MySQL), create
 a CSV output and have it in a sendable format for the user
 without creating a file.


$result = mysql_query(select * from something);

$output = fopen('php://output', 'w') or die(I messed up the php://
bit);

header(Content-type: application/octet-stream); //force download
while ($row = mysql_fetch_row($result)){
  fputcsv($output, $row);
}

//Look ma, no file!

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php