I’m doing something like the following to generate a file which get downloaded by the client:
$response = Yii::$app->getResponse();
$headers = $response->getHeaders();
$headers->set('Content-Description: File Transfer');
$headers->set('Content-Type: application/zip');
$headers->set('Content-Disposition: attachment; filename=' . basename($zipname));
$headers->set('Content-Transfer-Encoding: binary');
$headers->set('Expires: 0');
$headers->set('Cache-Control: must-revalidate');
$headers->set('Pragma: public');
$headers->set('Content-Length: ' . filesize($zipname));
return $response->sendFile($zipname);
and this downloads the file as $zipname which is a file named ‘email.zip’ in this case.
However, if there already exists a file with that name, it gets downloaded as:
email(1).zip
email(2).zip
email(3).zip
…
Is there any way to make it perform an overwrite of the file and always download it as ‘email.zip’?
The reason I ask is the file is then used by another automated process and that process relies on the file name and as such processes the wrong file.