Why PHP Script for read directory content no update directory changes at second execution

Posted on 2008-10-15
Medium Priority
Last Modified: 2013-12-13
I have php script for read a directory of image files, at first time, get the content right but at the second and another times result of php script is the same to de first read.
The content of directory is change for another php script. When I try to read de new content, result is the same every time run the php script.

Please, any idea for a solution?

Thank in advance

header( "cache-control: private" );
header( "pragma: no-cache" );
header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"."\n";
$directory = "../".$_GET['directory'];
echo "<gallery>"."\n";
echo "</gallery>";
function ExportDirectoryXML($base)
	if ($dir = @opendir($base))
		while ($file = readdir($dir))
			if ($file{0} != ".")
				if (is_dir($base . "/" . $file))
					$ext = @substr($file, (@strrpos($file, ".") ? @strrpos($file, ".") : @strlen($file)), @strlen($file));
					$fname = basename($file,$ext);
					$imgsrc= $base . "/" . $file;
					$imgsrc= substr($imgsrc, 3);
					echo "<image>"."\n";
					echo "<label>".$file."</label>"."\n";
					echo "<path>".$imgsrc."</path>"."\n";
					echo "</image>"."\n";
		} //end while 
	} // end if
} //end function 

Open in new window

Question by:Myshka
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 40

Expert Comment

by:Richard Quadling
ID: 22722570
What version of PHP?
LVL 40

Expert Comment

by:Richard Quadling
ID: 22722589
The script you've got doesn't change anything, just reports back the files found.

What changes are made to the files?

Author Comment

ID: 22722784
This is the case:

1. I use above script for read directory content of images files. For example, result are 10 image files content.
2. I use another script for add new image files to the same directory read from 1. For example, add 20 new image files to directory.
3. I execute again de first script for reread directory content, but result only show first 10 image files hoe directory content, not 30 image files how there are.

Php version is 5.x
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

LVL 40

Expert Comment

by:Richard Quadling
ID: 22722958
Are you sure the second script is writing to the correct folder?

Author Comment

ID: 22723082
Yes, I see directory content from another program and directly.
First, I see all is correct before request a solution!

I think in cache problem or php  refreshing content.
LVL 40

Accepted Solution

Richard Quadling earned 2000 total points
ID: 22723220
Is your browser set to always go to the internet for EVERY request? In IE at least, it can be set so that you only get 1 page, the rest are cached.

You can add the following headers to help ...

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past



Author Comment

ID: 22723267
You are fantastic, all is ok now.
Very tanks.

Author Closing Comment

ID: 31506316
Thank, you are my good
LVL 40

Expert Comment

by:Richard Quadling
ID: 22723340
Glad to have helped.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question