Jump to content

Refresh page when a file is uploaded


rullbandspelare

Recommended Posts

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).

 

<?php 
   function file_type($file){
       $path_chunks = explode("/", $file);
       $thefile = $path_chunks[count($path_chunks) - 1];
       $dotpos = strrpos($thefile, ".");
       return strtolower(substr($thefile, $dotpos + 1));
       $bild = $_POST["bild"];
   }
   $file_count = 0;
   $path = "../images/";
   $file_types = array( 'jpg', 'png', 'gif');
   $p = opendir($path);
       while (false !== ($filename = readdir($p))) {
           $files[] = $filename;
       }
   sort($files);
       foreach ($files as $file) {
           $extension = file_type($file);
           if($file != '.' && $file != '..' && array_search($extension, $file_types) !== false){
               $file_count++;
               echo '<a href="../index.php"target="_top"><img src="'.$path.$file.'" width="110" height="90"></a><br>'.$file.''.'<br>
';
           }
       }
   if($file_count == 0){
       echo "<b>EMPTY</b>";
   }
?>

 

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!

 

/tomas

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.