JS alert that links to a file
JS alert that links to a file
am 27.07.2009 04:55:14 von Skip Evans
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: JS alert that links to a file
am 27.07.2009 05:28:03 von Paul M Foster
On Sun, Jul 26, 2009 at 09:55:14PM -0500, Skip Evans 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!
Not sure I understand your question, but there is a function called
alert() in javascript. It opens a window with your error message in it.
I don't know of a way to trigger this from PHP, since PHP is server-side
and Javascript is client-side. You might be able to have javascript scan
for the existence/closing of the file in question and then alert the
user. Or you could have PHP, when the file is complete, launch a new
page which contains the javascript code to alert the user.
Paul
--
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: JS alert that links to a file
am 27.07.2009 05:39:25 von LinuxManMikeC
On Sun, Jul 26, 2009 at 8:55 PM, Skip Evans 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
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename=3D"file.csv"');
echo 'field1,field2,field3,field4';
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: JS alert that links to a file
am 27.07.2009 05:57:33 von Skip Evans
LinuxManMikeC wrote:
>
>
> header('Content-type: text/csv');
> header('Content-Disposition: attachment; filename="file.csv"');
> echo 'field1,field2,field3,field4';
> ?>
>
Okay, right, I remember this.
But it has to be in it's own file, otherwise you get the
'headers already sent error', right?
Is there any way around that? Any way to get it right at the
end of where the file is created???
Thanks!
Skip
--
====================================
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: JS alert that links to a file
am 27.07.2009 08:28:37 von List Manager
Skip Evans wrote:
> LinuxManMikeC wrote:
>>
>>
>> header('Content-type: text/csv');
>> header('Content-Disposition: attachment; filename="file.csv"');
>> echo 'field1,field2,field3,field4';
>> ?>
>>
>
> Okay, right, I remember this.
>
> But it has to be in it's own file, otherwise you get the 'headers
> already sent error', right?
>
> Is there any way around that? Any way to get it right at the end of
> where the file is created???
>
> Thanks!
> Skip
>
No, what he gave as an example was just right.
only if you try calling header() after you echo something will it give you the header's already sent
error.
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: JS alert that links to a file
am 27.07.2009 14:37:12 von Skip Evans
Hey all,
With LinuxMan's help I got this working. It was a bit tricky
as it's an AJAX environment, but what I did was create a
separate page with code similar to what he has below and then
call it from the JS side and it works great.
Thanks all, and especially LinuxManMikeC for the key!
Skip
Skip Evans wrote:
> LinuxManMikeC wrote:
>>
>>
>> header('Content-type: text/csv');
>> header('Content-Disposition: attachment; filename="file.csv"');
>> echo 'field1,field2,field3,field4';
>> ?>
>>
>
> Okay, right, I remember this.
>
> But it has to be in it's own file, otherwise you get the 'headers
> already sent error', right?
>
> Is there any way around that? Any way to get it right at the end of
> where the file is created???
>
> Thanks!
> Skip
>
--
====================================
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php