user927774
user927774

Reputation: 43

php scripts in the html file

I am developing an application where i am capturing images from a camera and streaming them online. To capture images i am using an opencv code. It stores(rewrites) the image on the same image file on server. This image is then streamed online. However if the streaming and storing take place simultaneously then the image gets corrupt. So i have synchronized those processes using system locks. The html page that checks that reloads the image every 2 secs checks if the img file has a system lock. If yes then it doesn't reload the image. So to check whether the file is locked or not i have to put some php code in my html file. I believe that my code is sytactically correct. Yet it is not giving the desired output.

 <html>

 <head>

 <!--to keep requesting the server new page without displaying the image from the cache pragma
  is used -->
 <META HTTP-EQUIV="Pragma" CONTENT="no-cache">

 <title>YOUR SITE TITLE GOES HERE</title>
 <style type="text/css">
    #imgJSselbox{
        position: absolute;
        margin: 0px;
        padding: 0px;
        visibility: hidden;
        width: 0px;
        height: 0px;
        border: 1px solid #006;
        color: #fff;
        background-image: url(selection_area.gif);
        z-index: 20;
    }
 </style>
 <script type="text/javascript" src="globalvar.js"></script>
 <script language="Javascript">

       var x = 2;
       var y = 1;
       var now;

  function startClock() {
        x = x-y;
        document.form1.clock.value = x;
   <?php
       $fp1=fopen("a.jpg","r");
       $fp2=fopen("b.jpeg","r");
       if(flock($fp1,LOCK_EX|LOCK_NB)==0 && flock($fp2,LOCK_EX|LOCK_NB)==0)
     $x=1;
       else
     $x=0;
    ?>

    var ch;
    ch=<?php echo $x; ?>

     if (x < 1 && ch==1) reload();
    <?php
        $fp1=fopen("a.jpg","r");
        $fp2=fopen("b.jpeg","r");
        flock($fp1,LOCK_UN); 
        flock($fp2,LOCK_UN);
    ?>
    timerID = setTimeout("startClock()", 1000);
   }

   function reload()
   {
        now = new Date();
         <!-- to pass the new image to the src -->
        var camImg = "a.jpg" + "?" + now.getTime();
        document.campicture.src = camImg;
        var crpImg = "b.jpeg" + "?" + now.getTime();
        document.croppic.src = crpImg;  

  x = 2;
        document.form1.clock.value = x; 
    }

    </script>
    <script type="text/javascript" src="image_cropper.js">
    document.form1.x-coord.value=x1;
    document.write(x1);


    </script>

    <script>
    function window.open('im','imgg')
    {
           window.open('im','imgg');
    }
    </script>
    </head>
     <body bgcolor="white" onLoad="startClock()">

    <center>

     <font size=-1>

     <h1>AYS WEBCAM PAGE</h1>

     <h2>This page loads images and refreshes them after every given interval of time keeping
     the same name of the image file</h2><p><br />
<div id="imgJSselbox"></div>
</center>
      <img name="campicture" src="a.jpg" id="testimage" border=1 width=640 height=480
       alt="AYS    
         founder's IMAGE" onClick="getImageCropSelectionPoint
        'testimage',event,document.form1);">
             ====>>ROI==>> 

<img name="croppic" src="b.jpeg" width=320 height=240 alt="cropped_image">
<center>
       <form NAME="form1"action="image_cropper.php" method="POST"><b><font size="-1"
       face="Arial">AutoReload in :==> </font>

        <input TYPE="text" NAME="clock" SIZE="2" VALUE="5"> <font size="-1"
        face="Arial">seconds.</font></b><br />
<br><br><input type="button" value="Crop" onclick= setImageCropAreaSubmit
       ("image_cropper.php",'testimage')><br><br>
       </center>
       <!-- <input type="text" name="x-coord" value=""><br>
 <input type="text" name="y-coord" value=""><br>
 <input type="text" name="wid" value="" ><br>
 <input type="text" name="hght" value="" ><br>
       -->
       </form>
       </body>

      </html>

Thank you

Upvotes: 1

Views: 235

Answers (1)

uınbɐɥs
uınbɐɥs

Reputation: 7351

Your problem is in the code timerID = setTimeout("startClock()", 1000);.

Use timerID = setTimeout(startClock, 1000); instead.

See window.setTimeout - MDN.

Upvotes: 1

Related Questions