Solved

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

Posted on 2008-10-15
9
211 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
  • 5
  • 4
9 Comments
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
What version of PHP?
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
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
Comment Utility
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
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Are you sure the second script is writing to the correct folder?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Myshka
Comment Utility
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:
RQuadling earned 500 total points
Comment Utility
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
Comment Utility
You are fantastic, all is ok now.
Very tanks.
0
 

Author Closing Comment

by:Myshka
Comment Utility
Thank, you are my good
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Glad to have helped.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now