简体   繁体   中英

Internal Server Error readfile

I have a view-script which opens a pdf-file, it looks like follows:

<?php
$this->title = 'arbeitskalender';
//ini_set('display_errors',1);
header('Content-Type:application/pdf');
header('Content-Disposition', 'attachment; fileName=arbeitskalender.pdf');
readfile('./pdfs/arbeitskalender.pdf');
?>

On my localhost (wamp-server) it works well and the file opens without any error, uploaded to my webspace (not my own server, only a webspace) I get

internal server error

.

What's the problem? Is there a possibility to get a more informative error message? Because it is not my server, I can't have a look in the server log.

Yes, a lot of:

  • check the network tab in your developer bar. Eventually, turn off (starts the header lines with //) your headers in your script to see the error message (for debugging)
  • check the logfiles of your framework (if you use)
  • check if your application can write log entries
  • enable and display errors (see Showing all errors and warnings )
  • check if php can read the file (permissions and existing of the file)
  • check if you only get the internal server error on this page

Looking to your script:

  • what's $this? I don't see a class definition
  • can php find the file?

Check ./pdfs/arbeitskalender.pdf permissions. I guess it's not readable for apache user

I checked all your suggestions, I learned some more, but couldn't solve the problem. I found another codesnippet which doesn't use readfile and so far this works fine.

<?php
require_once 'Zend/Pdf.php';

header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename=arbeitskalender.pdf');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression','0');
echo file_get_contents("./pdfs/arbeitskalender.pdf");

?>
<html>
<body>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM