Bir REST API'sinden bir Byte Array alıyorum. Sonra bu bayt dizisinden yerel bir dosya oluşturuyorum. Ve bu dosyayı ZF2 ile tarayıcıya gönderebilirim. ZF2 denetleyicisi eylem içerisindenZF2 Bayt dizisi ile akış
Kodu:
file_put_contents($fullpath, $rawPdf);
$headers = new \Zend\Http\Headers();
$contentDisposition = ($view == 'inline') ? 'inline': 'attachment';
$headers->addHeaders(array(
'Content-Disposition' => $contentDisposition . '; filename="' . basename($fullpath) . '"',
'Content-Type' => 'application/pdf',
'Content-Length' => filesize($fullpath),
'Expires' => '@0',
'Cache-Control' => 'must-revalidate',
'Pragma' => 'public'
));
$response = new \Zend\Http\Response\Stream();
$response->setStream(fopen($fullpath, 'r'));
$response->setStreamName(basename($fullpath));
$response->setStatusCode(200);
$response->setHeaders($headers);
return $response;
Ama doğrudan yerel bir dosya oluşturmadan tarayıcıya bayt dizisi gönderir.
Akışı ($ response-> setStream()) Byte Array ile nasıl ayarlayabilirim? Byte Array ile bir kaynak oluşturmak, ancak yerel bir dosya oluşturmadan nasıl oluşturulur?
düz eski PHP ile bunu yapabilirim:
$rawPdf = '';
array_walk($byteArray, function($value) use (&$rawPdf) {
$rawPdf .= chr($value);
});
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="Bericht.pdf"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
echo $rawPdf;
Sana $ Yanıt niteliğinde> setContent ($ rawPdf) yapmak zorunda düşünüyorum istediğini uyacak şekilde adapte edebilir; – peterpeterson
Bir dosyayı "php: // output" ve "force" dosyasına yazabilirsiniz – ceadreak