4 Replies - 601 Views - Last Post: 07 February 2012 - 11:51 AM Rate Topic: -----

Topic Sponsor:

#1 cesarwj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-January 12

how to call SAVE AS dialogue box?

Posted 06 February 2012 - 02:36 PM

Hi,

Somebody know how to call Save as dialog box ?

I want the system ask the user the path to download the CSV file.

How to works my code: The user fill the form, click on submit and I work with the data from POST to create a CSV file. then, after it, I want to show AUTOMATICALLY the Save as dialog box to ask him the path (from your PC) to download.

I tryed with javascript, but after create the CSV the user needs to click on Save as button.

I tryed with Header, but I think that its doensīt work because before Header I have code that works with the POST.

I have a code that in the final save the CSV file to user machine, but donīt know how to ask him.

Somebody know how can I do it?

tks

Is This A Good Question/Topic? 0
  • +

Replies To: how to call SAVE AS dialogue box?

#2 creativecoding  Icon User is online

  • Hash != Encryption
  • member icon

Reputation: 412
  • View blog
  • Posts: 2,418
  • Joined: 19-January 10

Re: how to call SAVE AS dialogue box?

Posted 06 February 2012 - 03:30 PM

Just have your javascript run once the page is done loading instead of on a click.
Was This Post Helpful? 0
  • +
  • -

#3 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1760
  • View blog
  • Posts: 2,693
  • Joined: 08-June 10

Re: how to call SAVE AS dialogue box?

Posted 06 February 2012 - 03:42 PM

Are we talking about having the browser's Download dialog pop up, so the user can choose to download a file created by PHP?

This is usually done by either redirecting to the file (assuming it is saved in a public place) so that the HTTP server can send it like it normally would, or by setting response headers in PHP in such a way that the browser thinks it's downloading a file.

This is basically how the second method works:
<?php
// Process your POST data into a CSV file
// here. Make sure to print NOTHING! If you
// do print something, the next part will fail.

// I'm assuming that at this point, you have
// your data in a CSV file named "mydata.csv"
$file = "/path/to/mydata.csv";

// First, you need to set the headers, so that
// the browser knows to expect a CSV file download.
header("Content-Disposition: attachment; filename=" . basename($file));
header("Content-Type: text/csv");
header("Content-Length: " . filesize($file));

// You can also set Cache headers, to minimize the
// risk of the browser using old versions of the data.
header("Pragma: no-cache");
header("Expires: 0");
header("Cache-Control: must-revalidate");

// And then you just print out the file data for
// the browser to open or save.
readfile($file);

// And, even though it's kind of redundant in
// this case, it's always a good idea to explicitly
// exit the script at this point, to reduce the
// chance of something corrupting the file data.
exit;
?>


Was This Post Helpful? 3
  • +
  • -

#4 cesarwj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-January 12

Re: how to call SAVE AS dialogue box?

Posted 07 February 2012 - 04:10 AM

Tks by answear Atli and creativecoding.

Atli tks by code and your time.

Atli, I tryed to use your code and I canīt, because when I run your code the current data from form disappears (I want them in the current page) and because I canīt set the header at final code (if I do I receive the error:Warning: Cannot modify header information - headers already sent by (output started at C:\Arquivos de programas\EasyPHP-5.3.8.1\www\sd_2\convite-online.php:640) in C:\Arquivos de programas\EasyPHP-5.3.8.1\www\sd_2\convite-online.php on line 750) OR If set the header at beginning all my code that need to run after it doesnīt run.

I attached my code from application (convite-online.PHP) to u see how it work.
This post donīt give access to attach the file convite-online-CSV.PHP. Then create this file with this words:

João;Máāria;17:40;CPS;
Bira;Marcelo;Alencar;Aguiar;Marcio;Pedro;
Mafalda;Fer;įaãõ;Mama;

To run the "Click to download", change the line http://localhost/convite-online-CSV.csv' in the convite-online.PHP to your localhost/directory where is the application that I gave to u.

Put both files in the same directory and 1o select the file csv, 2o click on button upload and after it click in SAVE button. This is the button (SAVE) that I need in the final code to run the DOWNLOAD of the file convite-online-CSV.PHP.

I can do the download by the link "Click to download", but the PROBLEM is that I want to run it AUTOMATICALLY without the user click on this button. I want to run the download in the space ("//download here" - Find it in convite-online-CSV.php)just in final code of the SAVE button.

Can U give me a tip to run the download AUTOMATICALLY and without lost the data form in the current page?

tks,
cesar.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#5 cesarwj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-January 12

Re: how to call SAVE AS dialogue box?

Posted 07 February 2012 - 11:51 AM

Man, tks by all

I resolved my problem with

    <iframe src="http://localhost/sd_2/<?php echo $nome_arq ?>" >
        <p>Impossível gerar o arquivo, porque seu navegador não suporta Iframe! Atualize seu navegador</p>
    </iframe>



tks

This post has been edited by Jstall: 07 February 2012 - 03:03 PM
Reason for edit:: code tags

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1