Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on 

Trying to display file in browser with php

I have this code. This is the entire php file:
<?php
// read file & display. File passed in $_GET
$path = "../summsp/" . $_GET['file'];
echo get_file_contents($path);
exit;
?>

Open in new window


I execute it like this:

https://www.lakoshvac.com/disp_summary.php?file=18075summary.pdf

I get a blank screen.

The directory structure is in the attached file. I cannot show you the file contents (pdf) because it is sensitive.

Why do I get a blank screen?

Thanks
Server_dir_sructure.JPG
PHP

Avatar of undefined
Last Comment
Julian Hansen
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Richard Korts
Richard Korts
Flag of United States of America image

ASKER

Perfect. I figured the function was wrong because it was not bolded in my html editor, but sometimes, it doesn't bold them all.

Thanks.

Richard
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

No worries Richard,

I would suggest that HTML editors are generally quite poor when it comes to analyzing PHP. A proper IDE would be a better choice. Add in error_reporting and you'll see exactly what's going on at runtime. Without it, you're effectively black-boxing your script - allowing it to fail silently with no hint as to what went wrong.

Another tip - when developing, keep an eye on your browsers built-in development tools. Loading up the page you linked to responded with a 500 Internal Server Error, so that's a good indication that your code is not working properly.
Avatar of Richard Korts
Richard Korts
Flag of United States of America image

ASKER

It worked perfectly for me.

I'll ask the customer to try it.

Richard
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Also take a look at readfile() - this function exists for precisely this use case

<?php
// read file & display. File passed in $_GET
$path = "../summsp/" . $_GET['file'];

header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=filename.pdf");

readfile($path);

Open in new window

Avatar of Richard Korts
Richard Korts
Flag of United States of America image

ASKER

Thanks.

FYI, I don’t know if Paula got ahold of you, we need your help (paid) again on our Media Wiki site. If she has NOT contacted you, please contact her.

Thanks,

Richard
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Thanks Richard, will do
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo