473,472 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Show image while in background PHP script executes

realin
254 Contributor
hiya guys,

I have a question, i want to display the image which is above the page, while my script loads in the background.
This is a simple script which check for new messages in my mailbox, so it is more like GMAIL's loading bar which is shown just before we land into our mailboxes.

Guys, how do i do it ? Because i have tried ob_start and ob_end_flush, but with no luck i am unable to see the image before script terminates. The whole data is shown into browser in one go. How do i slice it ..

The piece of code is like this ::

[PHP]
<?php
require_once("lib/POP3.php");
include('lib/mimeDecode.php');
require_once("../config/config.inc.php");

echo '<img src="loader.gif" />';



function gmail($em){
$start=strrpos($em,"&lt;");
$end=strrpos($em,"&gt;");
$len=$start+4;
$email=substr($em,$len,$end-$len);
return $email;
}

/****************** Function to parse message and splits the needful into parts *******************/
function parse_output(&$obj, &$parts){

if(!empty($obj->parts)){
for($i=0; $i<count($obj->parts); $i++)
parse_output($obj->parts[$i], $parts);

}else{
$ctype = $obj->ctype_primary.'/'.$obj->ctype_secondary;
switch($ctype){
case 'text/plain':
if(!empty($obj->disposition) AND $obj->disposition == 'attachment'){
$parts['attachments'][] = $obj->body;
}else{
$parts['text'][] = $obj->body;
}
break;

case 'text/html':
if(!empty($obj->disposition) AND $obj->disposition == 'attachment'){
$parts['attachments'][] = $obj->body;
}else{
$parts['html'][] = $obj->body;
}
break;

default:

$parts['attachments'][] = $obj->body;
$parts['attachments']['name']=$obj->ctype_parameters['name'];
}
}
}
/*************** Variable Initialization ************/

$user='realin@domain.com';
$pass='realin';
$host='mail.domain.com';
$port="110";
$commid=(int)"6";
/*@ var total number of messages
in the inbox */
$nTotal="";

/* @var Messages which are
being retrieved */
$retr="";


$my=array();
$data=array();
$obj=&new Net_POP3();

$obj->connect("$host","$port");
$ret=$obj->login($user , $pass,'USER' );
if(is_object($ret))
echo "Invalid Username/Password";

/********** Gets the office status of the mailbox, viz number of messages,size,UID *************/
$listing=$obj->getListing();



foreach($listing as $l){
$id=$l["msg_id"];
$head[$id]=$obj->getParsedHeaders($id);
$body[$id]=$obj->getMsg($id);
}
?>
[/PHP]
May 19 '08 #1
20 13341
hsriat
1,654 Recognized Expert Top Contributor
This is a JavaScript thing, something like this...

[php]<?php

//start sessions or whatever...

//send headers.....

echo "<script type=\"text/javascript\">document.write('<div id="loading">Loading...</div>')";

//do your php processing....

//and send the body tag like this..
echo "<body onload=\"this.style.display=''; document.removeChild('loading');\" style=\"display:none;\">[/php]

Not tested, but this may work.
May 19 '08 #2
realin
254 Contributor
This is a JavaScript thing, something like this...

[php]<?php

//start sessions or whatever...

//send headers.....

echo "<script type=\"text/javascript\">document.write('<div id="loading">Loading...</div>')";

//do your php processing....

//and send the body tag like this..
echo "<body onload=\"this.style.display=''; document.removeChild('loading');\" style=\"display:none;\">[/php]

Not tested, but this may work.

thanks buddy,

gonna try now ..

cheers !!
May 19 '08 #3
hsriat
1,654 Recognized Expert Top Contributor
thanks buddy,

gonna try now ..

cheers !!
Do some changes if it didn't work, but I think this thing will work.

Regards
May 19 '08 #4
realin
254 Contributor
Not tested, but this may work.
Din work for me mate :((
May 19 '08 #5
hsriat
1,654 Recognized Expert Top Contributor
Din work for me mate :((
What did you try?
May 19 '08 #6
rpnew
188 New Member
This is a JavaScript thing, something like this...

[php]<?php

//start sessions or whatever...

//send headers.....

echo "<script type=\"text/javascript\">document.write('<div id="loading">Loading...</div>')";

//do your php processing....

//and send the body tag like this..
echo "<body onload=\"this.style.display=''; document.removeChild('loading');\" style=\"display:none;\">[/php]

Not tested, but this may work.
Hi,
Can you tell me how would you execute javascript if the PHP hasn't finished executing. As it hasn't finished executing PHP it wont appear even on client browser and as per my knowledge javascript will work on client side only and that too after the javascript code is loaded..

Let me know if i'm wrong somewhere...

Regards,
RP
May 19 '08 #7
rpnew
188 New Member
Hi,
According to me you need to use Ajax for that.
Load whole page with Ajax. Display whatever you want to display on page on loading and in backgraound call your PHP script and then when reply comes back replace/hide your image and load the result...
And as per my knowledge even Google has used Ajax....

Regards,
RP
May 19 '08 #8
realin
254 Contributor
Hi,
According to me you need to use Ajax for that.
Load whole page with Ajax. Display whatever you want to display on page on loading and in backgraound call your PHP script and then when reply comes back replace/hide your image and load the result...
And as per my knowledge even Google has used Ajax....

Regards,
RP

kewll..
that is the only option left now.. and you are right in saying taht first php will execute and then the compiled thing is returned to client i.e. browser thru RESPONSE headers and then JS comes into play

true :)
May 19 '08 #9
rpnew
188 New Member
Hi,
I came up with this solution.
AJAX+PHP Solution....
HTML page which calls the PHP script
PHPAjax.html
[HTML]
<html>
<head>
<script type="text/javascript">
document.write('<div id="loading">Loading...</div>');
//Ajax Function
function getHTTPObject()
{
var xmlhttp;
if (window.ActiveXObject)
{
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E)
{
xmlhttp = false;
}
}
}
else
{
xmlhttp = false;
}
if (window.XMLHttpRequest)
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch (e)
{
xmlhttp = false;
}
}
return xmlhttp;
}
//HTTP Objects..
var http = getHTTPObject();

//Function which we are calling...
function AjaxFunction()
{
url='PHPScript.php';
http.open("GET",url, true);
http.onreadystatechange = function()
{
if (http.readyState == 4)
{
//Change the text when result comes.....
document.getElementById("loading").innerHTML=http. responseText;
}
}
http.send(null);
}
</script>
</head>
<body onload="AjaxFunction()">
</body>
</html>
[/HTML]

Background PHP Script
PHPScript.php
[PHP]
<?php
sleep(10);
echo "I'm from PHP Script";
?>
[/PHP]

Save both the file in same directory. From browser execute the HTML file... It will show you 'loading...' at first wait for 10 seconds.. and you will see the message changing to "I'm from PHP Script".. if everything works fine....

Let me know if you find any problem or if it helps...

Regards,
RP
May 19 '08 #10
rpnew
188 New Member
And can anyone tell me.. what is wrong with code tags here on site..
I cant get any tag working... everything shows up as

[HTML]
something
[/HTML]
eventhough i'm using Mysql, PHP or HTML tags...
Anyways... Going home.. see you tomorrow... bbye...
Regards,
RP
May 19 '08 #11
Atli
5,058 Recognized Expert Expert
And can anyone tell me.. what is wrong with code tags here on site..
The highlighting software was causing problems and was removed.
I do believe they are searching for alternatives tho.
May 19 '08 #12
hsriat
1,654 Recognized Expert Top Contributor
And gmail came back with a loading bar...
I was expecting that though....

Now how to make that?
May 19 '08 #13
dlite922
1,584 Recognized Expert Top Contributor
And gmail came back with a loading bar...
I was expecting that though....

Now how to make that?
To me this is not possible because PHP comes back after the processing is done.

I guess you'd split the PHP calling into multiple and call each one with Ajax and just update the bar with each call. A very stupid way of doing it, but that would have that affect; it will most definetly not be a smooth bar though (like vista style)

The most common thing is having a looping ajax loader .gif image.
May 20 '08 #14
hsriat
1,654 Recognized Expert Top Contributor
Well, I have another idea for realin, if he's interested.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><title>realin</title>
  3. <style type="text/css">
  4. body {background-image:url('loading_image.gif');}
  5. </style>
  6. </head>
  7. <body onload="document.getElementById('body').style.display=''; this.style.backgroundImage='none';">
  8. <div id="body" style="display:none;">
  9. <!--
  10.        body goes here
  11. -->
  12. </div>
  13. </body>
  14. </html>
May 20 '08 #15
realin
254 Contributor
guys,

really thanks a lot..
I gonna go for ajax like loading tomm morning..
Hope this works :)
May 20 '08 #16
coolsti
310 Contributor
*makes a note to myself: someday I am gonna learn Ajax, until then I keep sticking to my Javascript and an iframe doing my background queries and script calls*

:))
May 20 '08 #17
hsriat
1,654 Recognized Expert Top Contributor
*makes a note to myself: someday I am gonna learn Ajax, until then I keep sticking to my Javascript and an iframe doing my background queries and script calls*

:))
Believe me, its not a day's job. Rather its just minutes' job, if you know JavaScript.
May 20 '08 #18
coolsti
310 Contributor
Believe me, its not a day's job. Rather its just minutes' job, if you know JavaScript.
Yeah, I suspect that is true, probably why I haven't bothered yet :))
May 20 '08 #19
dlite922
1,584 Recognized Expert Top Contributor
Yeah, I suspect that is true, probably why I haven't bothered yet :))
"To fear the unknown is equal to fearing knowledge." --Dan M.
May 21 '08 #20
TheServant
1,168 Recognized Expert Top Contributor
"To fear the unknown is equal to fearing knowledge." --Dan M.
The fear of the LORD is the beginning of knowledge; fools despise wisdom and instruction. -- King Solomon & God

Been reading Proverbs recently!
May 21 '08 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Al Davis | last post by:
Note: I tried cross-posting this message to several newsgoups, including comp.lang.perl.misc, c.l.p.moderated, comp.infosystems.www.authoring.cgi, comp.lang.javascript and comp.lang.php. Nothing...
4
by: Dj Frenzy | last post by:
Hi, I know how to use javascript to change a background image to another background image, and how to change a background colour to another background colour. Is there a way to change an image to a...
4
by: Amir | last post by:
Hi, I'd like to know if it's possible to pass an image name (the IMG SRC attribute) from HREF element to a function that is activated by onClick event and creates a Web page. I have this HREF...
1
by: Littlefire | last post by:
Hi all I wrote a proxy script that fetches images out of a database and sends the data to the browser, using the Content-type header. For instance, if I'm loading a jpg image from the database,...
1
by: M | last post by:
Hi all, This is the script I use to find coordinates on a map and transfer them to textfields in the openerwindow. ++++++++++++++++++++++++ <HTML> <HEAD> <TITLEMouse Coords </TITLE> <script...
1
by: rsteph | last post by:
I've got some product information pages, with images and text, all setup within a table. I'm trying to add a small image in the upper right hand corner of the content div (where all the important...
6
by: yogarajan | last post by:
Hi All <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <style type="text/css"> #map {
16
by: stevedude | last post by:
CSS newbie again. I have a problem trying to get coffee mug images within anchor tags to center with my link text for a vertical list menu. If I use the horizontal/vertical properties of...
1
oranoos3000
by: oranoos3000 | last post by:
hi would you please help me i have a online shopping center that i show pictures of the my product in home page. in the InterExplorer pictures is shown correctly but in Firefox browser is shown...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.