473,788 Members | 2,814 Online
Bytes | Software Development & Data Engineering Community
+ 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("l ib/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($e m,"&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($o bj->parts[$i], $parts);

}else{
$ctype = $obj->ctype_primary. '/'.$obj->ctype_secondar y;
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_paramete rs['name'];
}
}
}
/*************** Variable Initialization ************/

$user='realin@d omain.com';
$pass='realin';
$host='mail.dom ain.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($r et))
echo "Invalid Username/Password";

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



foreach($listin g as $l){
$id=$l["msg_id"];
$head[$id]=$obj->getParsedHeade rs($id);
$body[$id]=$obj->getMsg($id);
}
?>
[/PHP]
May 19 '08 #1
20 13521
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\">do cument.write('< div id="loading">Lo ading...</div>')";

//do your php processing....

//and send the body tag like this..
echo "<body onload=\"this.s tyle.display='' ; document.remove Child('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\">do cument.write('< div id="loading">Lo ading...</div>')";

//do your php processing....

//and send the body tag like this..
echo "<body onload=\"this.s tyle.display='' ; document.remove Child('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\">do cument.write('< div id="loading">Lo ading...</div>')";

//do your php processing....

//and send the body tag like this..
echo "<body onload=\"this.s tyle.display='' ; document.remove Child('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">Lo ading...</div>');
//Ajax Function
function getHTTPObject()
{
var xmlhttp;
if (window.ActiveX Object)
{
try
{
xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
}
catch (e)
{
try
{
xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
}
catch (E)
{
xmlhttp = false;
}
}
}
else
{
xmlhttp = false;
}
if (window.XMLHttp Request)
{
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.onreadysta techange = function()
{
if (http.readyStat e == 4)
{
//Change the text when result comes.....
document.getEle mentById("loadi ng").innerHTML= http.responseTe xt;
}
}
http.send(null) ;
}
</script>
</head>
<body onload="AjaxFun ction()">
</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

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

Similar topics

5
3483
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 appeared on my news server, so I'm trying again - this time posting a separate copy of the message to each group. I'm thinking this should be fairly easy to accomplish - a quick and dirty ... what? ... script? program?
4
2489
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 backgound colour? I have a table with a background that has a picture. When the user hovers over the picture I want the background to change to the background colour of the rest of the page, as if to make the picture disappear.
4
4942
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 element: <A HREF onClick="showLargePicture()"><IMG HEIGHT=25 SRC="test01.jpg"></A>
1
2112
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, the script's output will be: header("Content-type: image/jpeg"); header("Content-length: <filesize-goes-here>"); print $imagedata;
1
2201
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 language="JavaScript"> <!--
1
3147
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 information is). I've got the product name at the top, left aligned and typically as a two lined header, and I'd like to add a small logo to the right of that, either right beside it, or in the far right corner. could anyone help me with how to set...
6
5426
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
4937
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 "background" or "background-image", the positioning only works with specifying pixels. If I specify the vertical position in pixels, the image gets cut-off at the bottom. I don't know what to do and would appreciate anyone's help. Specifically the code...
1
3813
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 properties alt in img tag istead of picture . place of the pictures is saved in the database(my database is with mysql) and in home page i fetch properties of the product and address of place that pictures is located output of the code in the...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5399
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
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 we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.