Re: JS alert that links to a file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jul 26, 2009 at 8:55 PM, Skip Evans<skip@xxxxxxxxxxxxxxxxx> wrote:
> Okay, I know I've done this before, but now I'm blanking out.
>
> I have code that creates a CSV file, and when it's done I want a JS alert to
> pop up and let them save the file.
>
> Isn't this some kind of alert() type call on the JS side???
>
> I know I've done this before and I've been on Google an hour now!
>
> --
> ====================================
> Skip Evans
> Big Sky Penguin, LLC
> 503 S Baldwin St, #1
> Madison WI 53703
> 608.250.2720
> http://bigskypenguin.com
> ------------------------------------
> Those of you who believe in
> telekinesis, raise my hand.
>  -- Kurt Vonnegut
>

If I understand you correctly, you have PHP code (lets call it
makecsv.php) that makes a CSV file and returns it to the user.  When
the user visits the script makecsv.php you want them to be prompted to
save the CSV file you just generated.  If that is what you meant, this
is not a JavaScript thing.  Just set the Content-type and
Content-Disposition headers in your PHP script.  The browser will then
bring up a "Save as" dialog box when it receives the output from the
script.  http://us.php.net/manual/en/function.header.php

<?php
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="file.csv"');
echo 'field1,field2,field3,field4';
?>

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux