Answer the question
In order to leave comments, you need to log in
How to display "save as" dialog in ZF2?
There is a form page. The user uploads the file and submits the form. xml file is generated.
How in Zend Framework to save the generated content by the user moss using the "save" dialog and after that the same page was shown to him?
The option with "save to the server, issue a download link" is not suitable.
Answer the question
In order to leave comments, you need to log in
The ZF2 way involves using the framework code to work with headers, and therefore:
$type = 'text/xml';
$data = '...';
$fileName = 'data.xml';
$response = $this->getResponse();
$response->setContent($data);
$headers = new \Zend\Http\Headers();
$headers->addHeaderLine('Content-Type', $type)
->addHeaderLine('Content-Disposition', 'attachment; filename="' . $fileName . '"')
->addHeaderLine('Content-Length', strlen($data));
$response->setHeaders($headers);
return $response;
$response = new \Zend\Http\Response\Stream();
$response->setStream(fopen($fileName, 'r'));
$response->setStatusCode(200);
...
$xml = "..."; // XML-данные
header('Content-type: text/xml');
header('Content-Disposition: attachment; filename="data.xml"');
header('Cache-Control: max-age=0');
echo $xml;
die();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question