View Full Version : Checking page size/whether image exists.
I have a php program running that can generate content and populate a page with different content based on many factors. However, there are certain circumstances where a blank page may be generated. Without going into the scope of the entire project, I want to know if it's possible that when my php page loads, I can 'check' to see if the page is blank, or 'check' to see whether a particular image has loaded, and if the page is blank or no image loaded, redirect to a new page.
Is there any way to do this? A function that can read the size of the current document would probably be sufficient.
11-05-2007, 05:10 PM
You can use output buffering to accomplish this. Start output buffering at the top of the script using ob_start(), then after the page is built you can us ob_get_contents() (http://us3.php.net/manual/en/function.ob-get-contents.php) to parse what was built, look for an image, etc. etc. then ob_flush() or redirect based on what you find.
11-05-2007, 05:12 PM
Blank pages are generally the result of a fatal error that isn't shown because you have error reporting off. You don't need to do any checking, just fix the underlying problem.
11-05-2007, 06:16 PM
I think rather than trying to figure out if a page is blank, why not keep track of those things with variables?
I'm assuming the page is supposed to load 1 or more things, and you don't know right now how many things loaded. And so if the page is empty go somewhere else.
You will have to explain more of the project in order to get a good answer.
Checking the output of the page is not a good method to see whether the page is "empty".
Thanks for the help so far. Not displaying an image is not the sign of an error in this particular project. The scope of the program is basically a gallery, and there are certain photos in certain spots that I will be adding. But for the time being, some of the records will be empty. There is a button to go to the next or previous record, however it stops at a record even when it is blank. What I want to do is if the image is not yet found, skip it and continue cycling records until it hits one that is populated.
Now the image is the only thing that displays on the page, other than the next and previous buttons so the document size will be very, very small if the image does not load.
I do see the reccomendation above and I'm going to try to work with it but I am unfamiliar with that function. If anyone can give any code examples or another method it would be appreciated. Thanks!
Am still looking to resolve this issue if anyone can help.
11-20-2007, 04:16 PM
A function that can read the size of the current document would probably be sufficient.
You can only read the current output that PHP is ready to send to the user.
You cannot detect what images are loaded, how much data the user actually received.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.