"header()"function related question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dhillarun
    New Member
    • Mar 2007
    • 18

    "header()"function related question

    Hi everybody,

    I displaying file download window("save-as dialog box") using PHP "header()" function.

    How to track that user have clicked "save" button or "cancel" button???
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    Hi I don't have a idea about how to trap the click events of the buttons that displays under out side the browser window.
    could you please submit the Script that you used for display the save as Dialog box.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      I doubt that you can access the download dialog from your scripts.

      I would think the browser runs any process, with access to you data, out of reach from any client script.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Originally posted by Atli
        Hi.

        I doubt that you can access the download dialog from your scripts.

        I would think the browser runs any process, with access to you data, out of reach from any client script.
        Exactly what I think. The whole download process is executed outside your program control.

        Ronald :cool:

        Comment

        • dhillarun
          New Member
          • Mar 2007
          • 18

          #5
          Code:
          function download()
          {
                  
                  header("Pragma: public");
                  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                  header("Expires: 0");
          
                  header("Content-Transfer-Encoding: binary");
                          header('Content-Disposition:' . $this->cont_dis .';'
                                  . ' filename="' . $this->name . '";'
                                  . ' modification-date="' . $this->mod_date . '";'
                                  . ' size=' . $this->fsize .';'
                                  ); 
                  header("Content-Type: "    . $this->mime );                     // MIME type
                  header("Content-Length: "  . $this->fsize);
                    
          
                 $total_bytes=readfile_chunked($this->path.$this->name);
          }
          
           function readfile_chunked($filename)
              {
                  $chunksize = 1*(1024*1024); // how many bytes per chunk
                  $buffer = '';
                  $cnt =0;
                  $handle = fopen($filename, 'rb');
          
                  if ($handle === false)
                  {
                          return false;
                  }
                  while (!feof($handle))
                  {
                          $buffer = fread($handle, $chunksize);
                          if(print $buffer)
                          {
                                  $cnt += strlen($buffer);
                          }
          
                  }
                  fclose($handle);
          
                  return $cnt; // return num. bytes delivered like readfile() does.
          
              }
          This is the code i am using to display "save-as" dialog box and to send content to the browser.

          Actually I am logging every download from my site. So , If the user clicks on "cancel" in the "save-as" dialog box, I should not log it.

          Pl provide any sol for this.

          Comment

          • ak1dnar
            Recognized Expert Top Contributor
            • Jan 2007
            • 1584

            #6
            Your script will call to a property (Download-Box) that is completely out side the browser window. so there is no way to trap that click events.

            so before you call for the headers you have to trap it. but in that case you can't determine whether the user completely downloaded the file or not only thing you can do by giving to buttons like Accept and Reject you have to trap the events.

            Comment

            • dhillarun
              New Member
              • Mar 2007
              • 18

              #7
              Originally posted by ajaxrand
              Your script will call to a property (Download-Box) that is completely out side the browser window. so there is no way to trap that click events.

              so before you call for the headers you have to trap it. but in that case you can't determine whether the user completely downloaded the file or not only thing you can do by giving to buttons like Accept and Reject you have to trap the events.
              Accept or Reject buttons will ensure only whether the user wants to download or not. But I wanted to know predict the button clicked in the "Save-As" dialog-box.

              Anyway, as per your answer I came to know that, the download dialog-box action is out of our control. So thanks.

              Thnx for all your replies.

              Comment

              Working...