An image is saved in the root directory.
The page “label.php” uses “readfile” to access and display the image using code like this:
$file = ‘../image.jpg’; // IN ROOT DIRECTORY
$type = ‘image/jpeg’;
header(‘Content-Length: ‘ . filesize($file));
The image then gets embedded into an html page and displayed like this:
Dear Customer, here is your image: <img src=”label.php?label=<?= $filename ?>.jpg”>
QUESTION: in the event of an error, how do I dipslay the readfile error on the customer’s html page?
Even though I have error trapping in the “readfile” code in “label.php” file — like if a parameter is missing, I’ll have exit( “NO IMAGE GENERATED” ). But this error message won’t display on the customer’s html page because html treats <?= $filename ?>.jpg” like it’s a real image instead of displaying the readfile’s “NO IMAGE GENERATED” exit error.
Make sense? No. I probably have to rewrite my question 😃
Source: ASK PHP QUESTIONS