Re: PHP events, listener, trigger

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
I am confusing about your question. You want to see a message/status 
when a function is working (file read/write). And change the status 
when it done. But php is a server side language. Its print/echos are 
sent to client whenever it finishes its execution all over the file. 
So if you print a message before the function(write file) and after 
the function, both message will show together when the clientside 
browsers loaded.
So, to do this task, i thing the best way is XMLHttpRequest (Ajax 
Technology). Here is an example for you... 

------ the file from witch the file update fuction will call -------

  <script type="text/javascript" language="javascript">

    var http_request = false;
	function getStatus()
	{
		document.getElementById("status").innerHTML 
= "Updating the file......";
		makeRequest('ReadWriteFile.php'); // parameter would 
be the file name(path) which process you file 
		document.getElementById("status").innerHTML 
= "Updated.";
	}
    function makeRequest(url) {
		//alert(url); return;
        http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject
("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = getResponse;
        http_request.open('GET', url, true);
        http_request.send(null);

    }
	function getResponse()
	{
		//catch the responseText data
		if (http_request.readyState == 4) {
            if (http_request.status == 200) 
			{
				alert(http_request.responseText);
            } else {
                alert('There was a problem with the request.');
				return;
            }
        }
	}
</script>
<input name="btnDo" type="submit" id="btnDo" value="Update File" 
onclick="getStatus()" />
<div id="status" ></div> 

---------- ReadWriteFile.php :: this file will update your file -----
-------

<?php
/* All of your code to read or write a file if read and want to 
return data then just print them*/
echo "All of your code to read or write a file will be in this file. 
Print data if you want too!!";
?>

Ok, If i can understand your problem, I think it may solve your 
problem. 

Thanks
Arshad


> --- mamontesines <mamontesines@xxxx> wrote:
> 
> > Hi,
> > 
> > Iam wondering has anyone tried a program that can do
> > an onUpdate
> > function? like for example I want to run a program
> > that waits until a
> > file is updated then a status report is displayed or
> > the file is
> > displayed on update/change without any use of loops.
> > 
> > like triggers....if a database is updated or new
> > data is inserted
> > there will be a trigger that launch a file or
> > function.
> > 
> > if anyone has done this may you share it to us?
> > 
> > thanks,
> > coco
> 









------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~-> 

PHP Data object relational mapping generator - http://www.meta-language.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux