FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP and images





Flakky
Hi,

I have written some scripts which do the following:
request.php - This script puts an 1 in a field in my mysql database.
check.php - This checks if 1 is in the field in my mysql database. If true print 1 and set the value to 0, if false print 0.

A program I wrote myself which is running on my computer visits check.php every second to see if the value is 1. If it is 1 it establishes an FTP connection, takes a snapshot of my webcam and uploads it as image.bmp.

My question is. I want request.php to set the field to 1 and refresh the page every 30 seconds. I don't know if there is an other way but I don't want to use Java for this.

Thanks in advance Smile
Marcuzzo
Java or JavaScript?

any way, there are several ways:
Javascript:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
 <script type="text/javascript">
 <!--
window.onload = function ()
{
    setTimeout ( "location.reload(true);", "30000");
}
 -->
</script>
 </head>
 <body>
</body>
</html>



Meta refresh:
Code:
<META HTTP-EQUIV=Refresh CONTENT="3; URL=http://www.yoursite.com/yoururl.php">


or php:
Code:
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "10";
header("Refresh: $sec; url=$page");
?>
Flakky
Thanks Marcuzzo. It works flawless. I used the PHP version at the end.
I don't really understand how it works as the source of the page shows no sign of anything newly added. How does the browser know to refresh?
EDIT: I am going to try out the other methods as the PHP one does not seem to work on Opera for Symbian S60 5th generation phones.
EDIT2: Meta refresh and PHP seem to work for my cellphone. I assume my phone is just incapable of counting 30 seconds correctly Wink
Fire Boar
Refreshing the page is usually overkill. If you need to reload text, consider using AJAX. If you need to reload just an image, you can use this trick...

Code:
var t = new Date().getTime();
document.getElementById('imagetoreload').src = 'file.jpg?q=' + t;


That should force the browser to reload the image.
Flakky
Fire Boar wrote:
Refreshing the page is usually overkill. If you need to reload text, consider using AJAX. If you need to reload just an image, you can use this trick...

Code:
var t = new Date().getTime();
document.getElementById('imagetoreload').src = 'file.jpg?q=' + t;


That should force the browser to reload the image.
I need to refresh the entire page as going to the script will update the system. Thanks for the tip anyways.
rickylau
Flakky wrote:
Fire Boar wrote:
Refreshing the page is usually overkill. If you need to reload text, consider using AJAX. If you need to reload just an image, you can use this trick...

Code:
var t = new Date().getTime();
document.getElementById('imagetoreload').src = 'file.jpg?q=' + t;


That should force the browser to reload the image.
I need to refresh the entire page as going to the script will update the system. Thanks for the tip anyways.
If your page is large and you are going execute part of the scripts and update the image only, you may consider creating a php with necessary script and a redirect to the image (or read and output the image if it has a static path) at last:
Code:
<?
// execute update script

// do redirect
header ('Location: path/to/image.jpg');

// or load the file directly
header ('Content-type: image/jpeg');
echo file_get_content ('path/to/image.jpg');
?>


With the javascript similar to Fire Boar's one (specifying php path for the img element instead of image path), it saves the bandwidth from transmitting page content which is unnecessary to refresh
Related topics
[tutor] How to protect images without htaccess using PHP
What do you use to make your page layout?
How To : Secure Your PHP Website
Dynamic PHP Images
Includ Images using PHP.
need a script.
Uplaoding images using php form :::: Help needed
As you can See My sig is very cool as it is but...
Index page for images, putting them all on one page 50fri$!!
Need Help with this CSS/HTML Thing again.
CSS for making images go through a php code.
PHP including images inside images
Need a captcha (anti-spam) added to my directory - 400FRIH$
ftp webwinkel installeren
URL shorten - HELP
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.