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

PDF document filename with inline downloads #388

Open
christatedavies opened this issue Aug 5, 2022 · 4 comments
Open

PDF document filename with inline downloads #388

christatedavies opened this issue Aug 5, 2022 · 4 comments

Comments

@christatedavies
Copy link

Hello there

I have found that if I run the following code:

$pdf->send("This-is_a_lovely__filename.pdf", true);

Then the PDF is automatically downloaded, with the correct filename. this is great

However, if I want the user to be able to view the PDF first, by using this:

$pdf->send("This-is_a_lovely__filename.pdf");

Then when the user saves the PDF, the filename becomes "document.pdf"

Is this a limitation of the browser? I'm using Firefox in this instance.

Thanks, Chris

@mikehaertl
Copy link
Owner

Honest answer: I don't know. The download logic was refined many times over the years and is based on the official PHP manual for readfile(). It should work - but browsers sometimes change their behavior so I just can't tell.

You can find our implementation here: https://github.com/mikehaertl/php-tmpfile/blob/master/src/File.php#L95

What you could do:

  • Create a simple test PHP script (without our library)
  • Build a download logic with readfile() to send some test PDF you have on your server
  • Try to mimic the same headers we have in our File.php and then play around with different header settings to find out if you can achieve what you want. Main thing to check is probably the Content-Disposition header.

If you find a combination that works you can report it here and we can see if we can improve the situation.

@mikehaertl mikehaertl changed the title PDF document filename PDF document filename with inline downloads Aug 26, 2022
@mikehaertl
Copy link
Owner

@christatedavies Any news here? Did you have a chance to reproduce the issue with a custom PHP script?

@christatedavies
Copy link
Author

Hi Mike. Not really, it looks like its an issue with the browser and how you can tell the browser to download or prompt. I don't fully understand it personally.

@mikehaertl
Copy link
Owner

Ok. I'll leave this open for now. If you or someone else finds a way feel free to post an update here so we can add it to the lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants