Create PDF with DOMPDF and Redirect

后端 未结 1 1120
没有蜡笔的小新
没有蜡笔的小新 2021-01-25 06:36

In a PHP project I need to Create a PDF file and redirect to another page when user clicks a Submit button. I have managed to create the pdf file using DOMPDF. PDF creation is d

1条回答
  •  北海茫月
    2021-01-25 07:16

    Answer to question

    For this to work you would need to move the second header call into the PDFRecipt file. At the moment with both of them in the one file your second call to header is overriding the first.

    Remember that headers are sent when the output is sent to the users browser, which is why you often see people calling exit() right after a header('Location: http://example.org');.

    So any subsequent calls to set the same header, in this case Location, will override the first until the headers are sent.

    It is also worth pointing out that you should be using full web URLs in Location:

    HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself

    according to the header page in the manual: http://php.net/manual/en/function.header.php

    Update from comments

    So you are using the stream() method to send the client the PDF - you cannot combine this with a Location: header. This is because DOMPDF has already flushed content to screen. I had assumed that your PDFRecipt.php file was storing the PDF to disk somewhere.

    See DOMPDF source code for more details: http://code.google.com/p/dompdf/source/browse/trunk/dompdf/lib/class.pdf.php#3061

    0 讨论(0)
提交回复
热议问题