1

//
Edit: I figured it out. Hours and hours of banging my head against a wall and it turns out all this needed was one simple line:

ob_clean();

Somewhere in some included file there's probably one line of whitespace that is screwing things up. ob_clean() will work for now. Thanks for the effort everyone who helped!
//

Working on a function that displays a random image from a custom endpoint. I have the custom endpoint set up, and am able to retrieve the url of the images. Here is some sample code:

$banner = "image/url/from/server/root";

if( !is_readable($banner)) {
                wp_die( "File is not readable: $banner" );
            }

// echo $banner;

$image    = file_get_contents( $banner );

header( 'content-type: image/jpg' );
header( "content-length: " . strlen( $image ) );

echo $image;

For some reason, this code is showing a blank image, not the image from the url. I have confirmed multiple times that the url is working by uncommenting echo $banner. I am seeing a url which I am assuming means the is_readable check is passed. I am a real noob when it comes to this stuff. The only thing I can think of is the header() function is somehow breaking my url?

closed as off-topic by Howdy_McGee, Mark Kaplun, fuxia Apr 7 '16 at 11:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?" – Howdy_McGee, Mark Kaplun, fuxia
If this question can be reworded to fit the rules in the help center, please edit the question.

  • do you have debugging enabled? – Milo Apr 2 '16 at 19:57
  • Yea it's set to true – James Hamann Apr 2 '16 at 21:27
  • Using is_readable you need to specify existing filename, even path exist ( without filename ) this function will always return true. – Jevuska Apr 3 '16 at 1:56
  • @Jevuska I'm sorry, can you elaborate on that? The filename is included in the URL I pass to it. Is there something else I'm missing? – James Hamann Apr 3 '16 at 2:52
  • 1
    I just needed ob_clean() guys. I'm going to go cry now. So many hours – James Hamann Apr 3 '16 at 5:03
0

I figured it out. Hours and hours of banging my head against a wall and it turns out all this needed was one simple line:

ob_clean();

Somewhere in some included file there's probably one line of whitespace that is screwing things up. ob_clean() will work for now. Thanks for the effort everyone who helped!

Not the answer you're looking for? Browse other questions tagged or ask your own question.