Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-15
9
Medium Priority
?
220 Views
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

<?php 
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";
ExportDirectoryXML($directory);
echo "</gallery>";
 
function ExportDirectoryXML($base)
{ 
	if ($dir = @opendir($base))
	{ 
		while ($file = readdir($dir))
		{ 
			if ($file{0} != ".")
			{ 
				if (is_dir($base . "/" . $file))
				{ 
				}
				else
				{
					$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 
		closedir($dir); 
	} // end if
} //end function 
?>

Open in new window

0
Comment
Question by:Myshka
[X]
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
9 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 22722570
What version of PHP?
0
 
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?
0
 

Author Comment

by:Myshka
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 40

Expert Comment

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

Author Comment

by:Myshka
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.
0
 
LVL 40

Accepted Solution

by:
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



http://docs.php.net/header

0
 

Author Comment

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

Author Closing Comment

by:Myshka
ID: 31506316
Thank, you are my good
0
 
LVL 40

Expert Comment

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

Featured Post

Technology Partners: 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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

604 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