Skip to content

Bug: CodeIgniter 4.0.3 Controller will not display pdf files in browser #3144

Description

@InsiteFX

Direction
We use github issues to track bugs, not for support.
If you have a support question, or a feature request, raise these as threads on our
forum.

Describe the bug
Forum reference: https://forum.codeigniter.com/thread-76768-post-377020.html#pid377020

The controller will not display pdf files in the wen browser using php headers.
` // Store the file name into variable
// The location of the PDF file on the server
$file = WRITEPATH . 'pdf/CodeIgniterAjaxPagination.pdf';
$fileName = 'CodeIgniterAjaxPagination.pdf';

	// Header content type
	header('Content-type: application/pdf');
	header('Content-Disposition: inline; filename="' . $fileName . '"');
	header('Content-Transfer-Encoding: binary');
	header('Content-Length: ' . filesize($file));
	header('Accept-Ranges: bytes');

	// Read the file
	readfile($file);`

Displays garbage characters.

CodeIgniter 4 version
Which version (and branch, if applicable) the bug is in.

CodeIgniter 4.0.3 Dev

Affected module(s)
Which package or class is the bug in, if known.

Something to do with the Controller were the code is ran from.

Expected behavior, and steps to reproduce if appropriate
A clear and concise description of what you expected to happen,
and how you got there.

It should have displayed the pdf file in the web browser chrome newest version.
Works file using straight php code script and loading form the folder directly into chrome.
.
Feel free to include a text/log extract, but use a pastebin facility for any
screenshots you deem necessary.

Context

  • OS: [e.g. Windows 10 x64]
  • Web server [e.g. Apache 2.4.3]
  • PHP version [e.g. 7.4.7]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions