I have a script for generate a .csv file and then download, but I need the dialog "Save as" for the user because I want a fast replace of the old file.
An easy example, I download the file "myFile.csv", then edit the data and download again for the refresh, but I need to REPLACE the file, and the browser download it as "myFile (1).csv", so I need to change the name. The point here, time is crucial.
I want the dialog "Save as" for the force as the same name and replace it.
A MWE:
<?php
header('Content-Type: text/csv;charset=Windows-1252');
header('Content-Disposition: inline; filename="myFile.csv";');
$delimiter = ',';
$f = fopen('php://output', 'w');
foreach ($cars as $car) {
fputcsv($f, [$car['id'],$car['model'],$car['color'],null], $delimiter);
}
fclose($f);
?>
EDIT: (Aclaration)
Tested on Google Chrome 68
I just realized that I did not mention an important point, when selecting the link for the download, the download automatically starts as myFile (1).csv and that's what I want to stop, I do not want the automatic download, I want the save dialog, save or cancel.
myfile_234wdfdf89sdmyfile_adf09dfjddfContent-Dispositionto instruct the browser and javascript can't do that...