Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7520613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:06:02+00:00 2026-05-30T02:06:02+00:00

I am creating a PDF file from raw binary data and it’s working perfectly

  • 0

I am creating a PDF file from raw binary data and it’s working perfectly but because of the headers that I define in my PHP file it prompts the user either to “save” the file or “open with”. Is there any way that I can save the file on local server somewhere here http://localhost/pdf?

Below are the headers I have defined in my page

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Transfer-Encoding: binary");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:06:03+00:00Added an answer on May 30, 2026 at 2:06 am

    If you would like to save the file on the server rather than have the visitor download it, you won’t need the headers. Headers are for telling the client what you are sending them, which is in this case nothing (although you are likely displaying a page linking to you newly created PDF or something).

    So, instead just use a function such as file_put_contents to store the file locally, eventually letting your web server handle file transfer and HTTP headers.

    // Let's say you have a function `generate_pdf()` which creates the PDF,
    // and a variable $pdf_data where the file contents are stored upon creation
    $pdf_data = generate_pdf();
    
    // And a path where the file will be created
    $path = '/path/to/your/www/root/public_html/newly_created_file.pdf';
    
    // Then just save it like this
    file_put_contents( $path, $pdf_data );
    
    // Proceed in whatever way suitable, giving the user feedback if needed 
    // Eg. providing a download link to http://localhost/newly_created_file.pdf
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a PDF file from a txt-template with tcpdf ([Example 8][1]). The txt-template
I have the following acceptance criteria for creating a pdf file from my asp.net
I have a PDF file that's an output from an OCR processor, this OCR
We are creating PDF documents on the fly from the database using PDFsharp .
I'm investigating the possiblity of creating PDF files from an embedded system, specifially an
I'm using html2fpdf for creating PDF documents. Now once I have created that, I
In a Java web application I am creating a zip file from various in-memory
I'd like to attach a PDF file stored as binary object in SQL Server
I'm working on creating PDF files in PHP with the R&OS PDF class (
An iPhone app which I am creating generates reports from a Core Data database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.