IMO edubem's answer जाने का रास्ता है, लेकिन आप कुछ इस तरह कर सकते हैं:
if (sha1(serialize(Map('/path/to/directory/', true))) != /* previous stored hash */)
{
// directory contents has changed
}
या एक और अधिक कमजोर/तेजी संस्करण:
if (Size('/path/to/directory/', true) != /* previous stored size */)
{
// directory contents has changed
}
यहाँ कार्यों उपयोग किया जाता है:
function Map($path, $recursive = false)
{
$result = array();
if (is_dir($path) === true)
{
$path = Path($path);
$files = array_diff(scandir($path), array('.', '..'));
foreach ($files as $file)
{
if (is_dir($path . $file) === true)
{
$result[$file] = ($recursive === true) ? Map($path . $file, $recursive) : $this->Size($path . $file, true);
}
else if (is_file($path . $file) === true)
{
$result[$file] = Size($path . $file);
}
}
}
else if (is_file($path) === true)
{
$result[basename($path)] = Size($path);
}
return $result;
}
function Size($path, $recursive = true)
{
$result = 0;
if (is_dir($path) === true)
{
$path = Path($path);
$files = array_diff(scandir($path), array('.', '..'));
foreach ($files as $file)
{
if (is_dir($path . $file) === true)
{
$result += ($recursive === true) ? Size($path . $file, $recursive) : 0;
}
else if (is_file() === true)
{
$result += sprintf('%u', filesize($path . $file));
}
}
}
else if (is_file($path) === true)
{
$result += sprintf('%u', filesize($path));
}
return $result;
}
function Path($path)
{
if (file_exists($path) === true)
{
$path = rtrim(str_replace('\\', '/', realpath($path)), '/');
if (is_dir($path) === true)
{
$path .= '/';
}
return $path;
}
return false;
}
स्रोत
2009-12-13 10:13:48
प्रतिक्रियाओं के लिए धन्यवाद, लेकिन आपके अधिकांश उत्तर एक स्क्रिप्ट के लिए मान्य नहीं हैं कि कई अलग-अलग प्रणालियों पर कई अंतिम उपयोगकर्ता उपयोग करेंगे। मैं इसे कार्यान्वित करने के बारे में बेहतर समझने के लिए, http://code.web-geek.net/ck-gallery – PHLAK