Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change content-disposition to attachment #50

Open
coxfrederic opened this issue Dec 12, 2022 · 6 comments
Open

Change content-disposition to attachment #50

coxfrederic opened this issue Dec 12, 2022 · 6 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@coxfrederic
Copy link

Is it possible to change it from inline to attachment?

We encountered an issue when downloading and according to https://stackoverflow.com/questions/11432538/file-download-in-chrome-appears-incorrect-file-name-pagename-aspx-it-worked-b inline is not supported

@spiritix
Copy link
Owner

If you're using the download output class, it's already implemented like you suggested: https://github.com/spiritix/php-chrome-html2pdf/blob/master/src/Spiritix/Html2Pdf/Output/DownloadOutput.php#L52

@coxfrederic
Copy link
Author

Yes I am aware of that but the problem is, when using that one, the file is downloaded automatically.
We want it to display inline, but when the user wants to download it, it gets downloaded as a PDF.

@coxfrederic
Copy link
Author

Now when the user wants to download it the Chrome browser says it's downloading index.php instead of the PDF

@spiritix
Copy link
Owner

Okay I see. The issue is that the RFC states:

If the disposition type matches "attachment" (case-insensitively), this indicates that the recipient should prompt the user to save the response locally

I don't see a way to use 'attachment' and still embed the file in the browser. Do you have an idea how to do that?

@coxfrederic
Copy link
Author

I think we need to look for a way to be able to use "inline" and somehow get the filename download to work correctly.
The strange thing is we get different results on Chrome on different environments (server vs locally on vagrant) and wether it is the result of a POST request vs a call without using POST.

I'll investigate more and when I have some clear results we can check the solution

@spiritix spiritix added enhancement New feature or request help wanted Extra attention is needed labels Dec 14, 2022
@spiritix
Copy link
Owner

I think the browser automatically uses the file name as in the URL. So in case of www.example.com/pdf.php it will be pdf.php. You could use rewrite rules to redirect a filename like /MyFile.pdf?id=1000 to /pdf.php?id=1000, that should work.

Leaving this issue open in case anybody has an idea on how to solve this in the backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants