Popup window with force-download but wanting window to close

Discussion in 'PHP' started by Choller, Dec 20, 2006.

  1. #1
    I have a popup window that prompts for a file download. HOwever I want the window to close after the user starts to download the file. I tried the following code but the window isn't closing (only if people click to NOT download the file).
    I don't understand why it's not closing. I am opening the popup window with a window.open command on the "main" page.
    
    <?php 
    $filename= $_GET['file'];
    $filename=$filename.'.qqc';
     header('Content-Description: File Transfer');
               header('Content-Type: application/force-download');
    	   header("Content-Disposition: attachment; filename=$filename; "); 
               header('Content-Length: ' . filesize($filename));
    ?>
    <script type="text/javascript">
    window.close();
    </script>
    PHP:

     
    Choller, Dec 20, 2006 IP
  2. weknowtheworld

    weknowtheworld Guest

    Messages:
    306
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you must launch a popup window that will close itself after a preset period of time...
     
    weknowtheworld, Dec 20, 2006 IP
  3. dshah

    dshah Well-Known Member

    Messages:
    1,840
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    115
    #3
    Since I don't know exact thing you are trying to do, I am just going take a guess-shot.

    Why you need to open popup window? If you set the content-type in out browser will give user option to save/open/cancel by itself (unless it can open it itself - like excel)

    If you have to submit the form, submit it to your main window it self - but the content type header in output will result into save/open/cancel dialog

    Hope this helps.
     
    dshah, Dec 20, 2006 IP
  4. Choller

    Choller Peon

    Messages:
    388
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm doing other things on submit, I tried combining them into one php page but it's not really possible (because i'm doing more stuff before the filedownload). That's why I want to do it this way (it's also not uncommon).

    weknowtheworld, i'll try using a timer.
     
    Choller, Dec 20, 2006 IP
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    When the user clicks on the Download link, which you provide, do an onclick attribute to the link: "javascript:window.close();"

    Peace,
     
    Barti1987, Dec 20, 2006 IP
  6. picking

    picking Peon

    Messages:
    501
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i will be using this, thanks for posting
     
    picking, Dec 20, 2006 IP