473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Redirecting output

I generate a string in PHP with headers that write a file to the disk.
(the user is asked whether to open it or to save it).

Using AJAX, the string is written to the screen instead. What I would
like to know is how to redirect the output to not be to the screen but
to open the file (as it is without AJAX). For other output I direct the
output to a names <divtag to appear on the screen. How do I specify
the target here?
Jun 27 '08 #1
5 1264
On Apr 20, 11:31 am, sheldonlg <sheldonlgwrote:
I generate a string in PHP with headers that write a file to the disk.
(the user is asked whether to open it or to save it).

Using AJAX, the string is written to the screen instead. What I would
like to know is how to redirect the output to not be to the screen but
to open the file (as it is without AJAX). For other output I direct the
output to a names <divtag to appear on the screen. How do I specify
the target here?
I'm not sure if I understood your question, but it seems you want to
use javascript to open and write a local file. Is that correct? If so,
then I must say that for security reasons, there is no way to open
local files using javascript in a web browser. At least, as far as I
know.

I don't know if it helps, but all you can do here, is send the data
from the client to the server and then write a file with that data 'on
the server'. On the client, I dont think it will be possible.
Jun 27 '08 #2
Rodrigo Dias Cruz wrote:
On Apr 20, 11:31 am, sheldonlg <sheldonlgwrote:
>I generate a string in PHP with headers that write a file to the disk.
(the user is asked whether to open it or to save it).

Using AJAX, the string is written to the screen instead. What I would
like to know is how to redirect the output to not be to the screen but
to open the file (as it is without AJAX). For other output I direct the
output to a names <divtag to appear on the screen. How do I specify
the target here?

I'm not sure if I understood your question, but it seems you want to
use javascript to open and write a local file. Is that correct? If so,
then I must say that for security reasons, there is no way to open
local files using javascript in a web browser. At least, as far as I
know.

I don't know if it helps, but all you can do here, is send the data
from the client to the server and then write a file with that data 'on
the server'. On the client, I dont think it will be possible.
Yes, it is and I have done it (sending commands built in PHP).

What happens is that there is a pop-up that asks the user whether he
wants to open the file or save it. He can also cancel. This satisfies
the security question because the user must give permission. In PHP
this is accomplished with the following header calls:

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . $excel_file_name);
header("Pragma: no-cache");
header("Expires: 0");

The result is as I stated above. I believe there are similar calls in
javascript, but I haven't used those before.
Jun 27 '08 #3
VK
On Apr 21, 3:34 pm, sheldonlg <sheldonlgwrote:
What happens is that there is a pop-up that asks the user whether he
wants to open the file or save it. He can also cancel. This satisfies
the security question because the user must give permission.
Not in the default browser security model. In in the default browser
security model Javascript has no access to the local file system _of
any kind_ - that includes any kind of runtime dialogs to beg a
permission from the user. It is very smart way to do because the
practice proved that end users very rarely are able to make an
educated decision "allow/don't allow" for security sensitive question:
thus an additional protection level is needed. Respectively to get a
permission to ask for a permission the script has to be properly
signed first. There is a trick for IE and Firefox to get such pop up
for some runtime generated content:
http://groups.google.com/group/comp....ab048d640b343b

I do expect that SaveAs exploit will be fixed sooner or later for IE -
if not already fixed. It also doesn't help for any other browsers
besides IE and Firefox.

This way just relax and use the standard age old server-side schema
which works just fine everywhere:

<form name="saver"
target="dumpster"
action="pushback.php">
<input type="hidden" name="data" value="">
</form>
<iframe name="dumpster"
src="blank.html"
style="display: none !important"></iframe>

then in your script:

document.forms['saver'].data.value = currentValue;
document.forms['saver'].submit();

then on your server pushpack.php returns data with octet-stream header
to trig Save As dialog.
Jun 27 '08 #4
On 21 Apr, 12:34, sheldonlg <sheldonlgwrote:
Rodrigo Dias Cruz wrote:
>I'm not sure if I understood your question, but it seems you want to
use javascript to open and write a local file. Is that correct? If so,
then I must say that for security reasons, there is no way to open
local files using javascript in a web browser. At least, as far as I
know.
Yes, it is and I have done it
No you haven't.
(sending commands built in PHP).
See, this is not javascript.
What happens is that there is a pop-up that asks the user whether he
wants to open the file or save it. He can also cancel. This satisfies
the security question because the user must give permission.
Once again, no javascript
Jun 27 '08 #5
sheldonlg wrote on 21 apr 2008 in comp.lang.javascript:
Rodrigo Dias Cruz wrote:
>On Apr 20, 11:31 am, sheldonlg <sheldonlgwrote:
>>I generate a string in PHP with headers that write a file to the
disk. (the user is asked whether to open it or to save it).

Using AJAX, the string is written to the screen instead. What I
would like to know is how to redirect the output to not be to the
screen but to open the file (as it is without AJAX). For other
output I direct the output to a names <divtag to appear on the
screen. How do I specify the target here?

I'm not sure if I understood your question, but it seems you want to
use javascript to open and write a local file. Is that correct? If
so, then I must say that for security reasons, there is no way to
open local files using javascript in a web browser. At least, as far
as I know.

I don't know if it helps, but all you can do here, is send the data
from the client to the server and then write a file with that data
'on the server'. On the client, I dont think it will be possible.

Yes, it is and I have done it (sending commands built in PHP).

What happens is that there is a pop-up that asks the user whether he
wants to open the file or save it. He can also cancel. This
satisfies the security question because the user must give permission.
In PHP this is accomplished with the following header calls:

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=" .
$excel_file_name); header("Pragma: no-cache");
header("Expires: 0");

The result is as I stated above. I believe there are similar calls in
javascript, but I haven't used those before.
Yes there are, in serverside javascript [ASP-Jscript].

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Christophe HELFER | last post by:
hi, I have some problem with redirecting input and output from a process. I can only use VB language (sorry...) Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) ...
6
by: Christophe Helfer | last post by:
hi, I have some problem with redirecting input and output from a process. Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) command line utility as redirecting its...
0
by: Christophe HELFER | last post by:
hi, I have some problem with redirecting input and output from a process. I can only use VB language (sorry...) Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) ...
8
by: Morpheus | last post by:
I am trying to test a function that outputs text to the standard output, presumably using a cout call. I do not have access to the source, but need to test the output. Is this possible? I can...
1
by: pp4175 | last post by:
Hello Everyone, I am currently working on writing a GUI wrapper for a Menu driven DOS Program. What I was looking on doing is redirecting stdout/stdin to a stream and read/write similar to a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.