How to show "Save as" window when downloading?

1

As I download the video that has the option to "save as" in php, I have already tried. it seems that something is missing, always downloading

index.php:

<form action="down.php" method="post" name="url">
<input name="url" type="text">
<input type="submit" value="Download">
</form>

down.php:

<?php
if(!empty($_POST['url'])){
  $fileName = $_POST['url'];
    header("Content-Type: video/mp4");
    header("Content-disposition: attachment; filename=\"video.mp4\"");
    readfile('video.mp4');
    exit;
}else{
    echo 'O video não existe.';
}
    
asked by anonymous 29.05.2017 / 23:32

1 answer

4

There's no way , the Save As dialog box is a user-choice browser option, you can not force it to appear via scripts, > server-side and neither client-side scripts (like JavaScript).

There are browsers that download directly, for example mobiles there are browsers that show such a dialog box to save by default, but the only thing you can do is to provide a link with an information saying:

  

Right click and select "Save as ..."

This is how the dialog box appears without configuring the browser

The user of a desktop browser decides if he wants to download directly (usually to Downloads folder), or if he is prompted for the dialog where he wants to save, for example, in Chrome if you navigate by typing in the address bar chrome://settings/?search=downloads , you'll notice this:

See that the option is disabled, if you enable this option, any download will have the dialog box asking if you want to Open or Save / Save you do not need to right-click / mouse, if it is disabled it will save directly to the default Downloads folder of your system (usually, but you can change the folder location).

    
29.05.2017 / 23:52