On Thu, 2006-08-10 at 01:20 +0900, Dave M G wrote:
> PHP List,
> 
> In the last stage of my current script, I need to take a bunch of data 
> from the database and put it into a text file for the user to save to 
> their computer and import into an application.
> 
> The file being created is just a list of Japanese words and definitions 
> delineated by tabs.
> 
> The file format should be a text file. Actually, it could also be CSV 
> file, since it's tab delineated data.
> 
> The application being imported to only accepts EUC-JP encoding for text 
> files that include Japanese text, so my data, which is stored in the 
> database as UTF-8, will need to be converted to EUC-JP at some point 
> along the way to being written to the file.
> 
> This file need not ever be stored on the server. In fact, I'd rather it 
> not so as to avoid any headaches with permissions settings (which always 
> give me a headache, but that's a rant for another day).
> 
> So, I'm looking on php.net for functions that would be able to create a 
> file out of some data and pass it along to the user.
> 
> But it seems that the assumption of all the file functions (that I've 
> found) such as fwrite(), fopen(), file(), readfile(), and others are all 
> about taking an existing file and working with it. And more importantly, 
> all of them seem to assume that the place where the file would be stored 
> is on the servers system, and not immediately passed on to the user.
> 
> I have a suspicion that this is one of those situations where the 
> starting point is assumed to be so simple that no one goes out of their 
> way to document or explain it.
> 
> I'm too lost to know where to begin.
> 
> How do I create a file that the user saves, and is not stored on the server?

It's all about the headers... I use the following:

    function uploadStream( $filename=null, $csv=null )
    {
        if( $csv === null )
        {
            $csv = $this->csv;
        }

        if( $filename === null )
        {
            $filename = 'download.csv';
        }

        header( "Content-type: text/csv" );
        header( "Content-disposition: inline; filename=$filename" );   

        echo $csv;

        exit();
    }

You can feel free to adapt it since I ripped it out of my CSV writer
service and so it won't work as-is.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

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

Reply via email to