By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,649 Members | 1,662 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,649 IT Pros & Developers. It's quick & easy.

Refresh page when a file is uploaded

P: 2
I have a directory that contains images wich are displayed with this code:
(All it does, is going through all the images in the directory and displays them).

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.    function file_type($file){
  3.        $path_chunks = explode("/", $file);
  4.        $thefile = $path_chunks[count($path_chunks) - 1];
  5.        $dotpos = strrpos($thefile, ".");
  6.        return strtolower(substr($thefile, $dotpos + 1));
  7.        $bild = $_POST["bild"];
  8.    }
  9.    $file_count = 0;
  10.    $path = "../images/";
  11.    $file_types = array( 'jpg', 'png', 'gif');
  12.    $p = opendir($path);
  13.        while (false !== ($filename = readdir($p))) {
  14.            $files[] = $filename;
  15.        }
  16.    sort($files);
  17.        foreach ($files as $file) {
  18.            $extension = file_type($file);
  19.            if($file != '.' && $file != '..' && array_search($extension, $file_types) !== false){
  20.                $file_count++;
  21.                echo '<a href="../index.php"target="_top"><img src="'.$path.$file.'" width="110" height="90"></a><br>'.$file.''.'<br>
  22. ';
  23.            }
  24.        }
  25.    if($file_count == 0){
  26.        echo "<b>EMPTY</b>";
  27.    }
  28. ?>
It is important that it is automaticaly refreshed when the directory content changes. Now I have put a
<meta http-equiv="refresh" content="20"> there.
But it is important that it does not refresh when no new images are arriving/leaving the directory.
I have some control on how the add/delete is carried out. So i could add a "flagfile" to indicate if something has been removed or added. and base the refresh on that ...or?

HELP! Can this be done with the help of AJAX?Any input is appreciated!

Nov 21 '07 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 16,027
Is this the upload page or another page which needs to be refreshed?
Nov 22 '07 #2

P: 2
Is this the upload page or another page which needs to be refreshed?
Im not sure what You mean?

That is the page that displays the images that are in a specific directory in the "htdocs" web tree. It is this page that needs to be refreshed when a new file is added/deleted.
The images goes there via ftp and are deleted with another php page.But there are also other ways images gets there.


Nov 22 '07 #3

Expert Mod 15k+
P: 16,027
With Ajax, you could check every few seconds(or is that too long?)

Make a request to the PHP script which can determine if a change has been made. The PHP script would return true or false and based on that, you could refresh the page.
Nov 22 '07 #4

Post your reply

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