NYCPHP Meetup

NYPHP.org

[nycphp-talk] Creating file for download on the fly? (Out of the office)

Ted Morawski ted at abptuf.org
Fri Jul 26 19:44:55 EDT 2002


I am currently on leave and will return to the office on
Monday, Aug. 5, 2002. If your issue is of critical importance,
please contact Albert Sunseri - sunseri at abpi.net or 
Luke Schnirring - luke at abpi.net . Thanks.

>>> talk 07/26/02 19:44 >>>

if your user are using excel-2000 you can use the xml speardsheet format.
there is documentation on it somewhere on msdn.microsoft.com , somewhere.
i use http://homepage.tinet.ie/~jmcnamara/perl/WriteExcel.html , perl
module. i beleive it writes in an older format, but i'm sure it will do, i
just like the simple interface. for the xml format i would just create a
file and in the save as, save as xml speardsheet and look at how it looks.
there is also a libxls right now i can't remember the link, its a c
library no documenation but you can look at the sample programs to get an
idea... not that simple.... maybe if your curious.

my defense:
i do it easily in perl becase perl like the php program gets its data from
a c++ generted xml file and both use the same exact parser. why c++ a
lot of things need to get generated on the fly (php to slow for it).

this is what i currently do on my site as far as headers... i'm sure i
didn't even think when i did this, i just probably copied from somewhere:

/* no cache */
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //always modified
header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0

/* application */
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: inline; filename=fund.xls");
header("Content-Description: PHP3 Generated Data" );
header("Content-Length: ".strlen($contents));
print $contents;

ciao i hope this helps.

On Fri, 26 Jul 2002, Oktay Altunergil wrote:

> I wouldn't call hitting something like that a Microsoft snag.. Exactly how unlucky are you ? :)
>
> Oktay
>
> On Fri, 26 Jul 2002 15:20:45 -0400
> "Freedman, Tom S." <tfreedma at ubspw.com> wrote:
>
> > Everything's working great.  That's exactly what I was looking for.
> >
> > I did hit a Microsoft snag, of course, which gave me a good hour and a half
> > of headaches.
> >
> > It turns out that the first two characters of a text file loaded into MS
> > Excel CANNOT be "ID".  Of course, I was calling my first column "ID".
> > Excel, upon finding those characters, assumes the file is a SYLK (symbolic
> > link) file, and tries to read it as such.  This fails, so you get the
> > cryptic error "SYLK: File format is not valid."  I spent at least an hour
> > trying to figure out what about my output was invalid (line terminators,
> > separators, possible bogus characters in the data), until I finally searched
> > the web in desperation and hit upon a Microsoft KB article acknowledging the
> > problem.  Just makes you wanna scream, sometimes.
> >
> > -Tom
> >
> > -----Original Message-----
> > From: Freedman, Tom S.
> > Sent: Friday, July 26, 2002 11:16 AM
> > To: NYPHP Talk
> > Subject: RE: [nycphp-talk] Creating file for download on the fly?
> >
> >
> > Thanks everyone!  I was unaware of the Content-disposition header.  I'll
> > give this a try as soon as I can!
> >
> > Thanks again,
> > Tom
> >
> > -----Original Message-----
> > From: Wellington Fan [mailto:beef at interport.net]
> > Sent: Friday, July 26, 2002 10:57 AM
> > To: NYPHP Talk
> > Subject: RE: [nycphp-talk] Creating file for download on the fly?
> >
> >
> > All,
> > I would add:
> >
> > header("Content-length: ".strlen($csvfilecontent));
> >
> > >-----Original Message-----
> > >From: Kayra Otaner [mailto:kayraotaner at yahoo.com]
> > >Sent: Friday, July 26, 2002 10:38 AM
> > >To: NYPHP Talk
> > >Subject: Re: [nycphp-talk] Creating file for download on the fly?
> > >
> > >
> > >Hi, I think this self explaining code helps :
> > >
> > >header("Content-disposition: filename=$filename.csv");
> > >header("Content-type: application/octetstream");
> > >header("Pragma: no-cache");
> > >header("Expires: 0");
> > >echo $csvfilecontent;
> > >
> > >
> > >PS : You need to use this code before any other output since header()
> > >function requires to be sent
> > >before anything else.
> > >
> > >
> > >Best
> > >
> > >Kayra Otaner
> > >
> > >
> > >--- "Freedman, Tom S." <tfreedma at ubspw.com> wrote:
> > >> Hi all, I've been a lurker for a couple months as I've been learning PHP,
> > >> and many of your suggestions have been really helpful.  I was hoping
> > someone
> > >> might have an idea on how to tackle an issue I haven't been able to find
> > any
> > >> info on.
> > >>
> > >> I'm currently working on a new version of a departmental intranet
> > website.
> > >> I have a database, and offer the users a search page that lets them query
> > it
> > >> in a variety of ways.  The new results page is not laid out in a grid, as
> > >> the old one was (we've added a lot of new fields, and the grid would be
> > too
> > >> packed).  Some users have requested the ability to download the data for
> > >> import into Excel (they used to just copy and paste the table in).  I've
> > >> figured out how to create a .csv file, and I could, theoretically, create
> > >> one every time someone runs a query, save it in a temp directory, and
> > >> include a link to it on the webpage.  We'd have to run a cleanup routine
> > >> every night, though, to delete all these .csv's on the server.  It seems
> > >> really clumsy to me.  What I'd like to do is put a link on the result
> > page
> > >> that, when clicked on, builds the .csv right then and offers it to the
> > user
> > >> for download.  Is this feasible, or should I just go with the temp
> > directory
> > >> full of reports?
> > >>
> > >> Thanks in advance,
> > >> Tom
> > >>
> > >
> > >
> > >__________________________________________________
> > >Do You Yahoo!?
> > >Yahoo! Health - Feel better, live better
> > >http://health.yahoo.com
> > >
> > >
> >
>
>
>






More information about the talk mailing list