File "version02.php"
Full Path: /home/analogde/www/Prog/File explorer/version02.php
File size: 4.3 KB
MIME-type: text/x-php
Charset: utf-8
<?php
$root_path = $_SERVER['DOCUMENT_ROOT'];
//echo $root_path;
//$path = "https://analog-design.net/Fusion/File explorer"; ///accent.php";
$path = "/home/analogde/www/Fusion/File explorer";
$file = substr( strrchr( $path, "/" ), 1) ;
$dir = str_replace( $file, '', $path ) ;
//echo " --->>> " .$file ."<br><br>";
//echo " --->>> " .$dir ."<br><br>";
$dir = substr($dir, 0, -1);
//echo " --->>> " .$dir ."<br><br>";
/****************************************************************/
$files = explore_folder($path);
//echo "<pre>";
//print_r( $files );
//echo "</pre>";
/****************************************************************/
//$path = getcwd() . "/accent.php";
//echo $path;
$path = "/home/analogde/www/Fusion/File explorer/pipo.php";
//$file = substr( strrchr( $path, "/" ), 1) ;
if (file_exists($path))
{
$array = [];
for ($x = 0; $x <= 1000; $x++)
{
$array[] = "***rev_" .$x ."***";
}
$filename = basename($path);
//
echo " Fichier que l'on recherche ... " .$filename ."<br><br>";
$array_search = [];
echo " Nombre de fichier dans le répertoire : " .count($files) ."<br><br>";
$n = count($files);
for ($x = 0; $x < $n ; $x++)
{
$str_search = "_" .$files[$x];
$res = strpos($str_search, $filename);
// on a trouvé
if ($res == "1" )
{
if ( $files[$x] != $filename)
{
//echo "Detection ........................................" ."<br>";
$array_search[] = $files[$x];
}
}
}
if( sizeof($array_search) == 0 )
{
$datetime = date("d-m-Y_H:i:s");
$newfile = $filename ."_" .$datetime ."_" .$array[0];
echo "Initial " .$newfile;
copy($filename, $newfile);
}
if( sizeof($array_search) != 0 )
{
echo "Increment";
echo "<br><br>";
echo "<pre>";
print_r($array_search);
echo "</pre>";
$n = count($array_search);
$array_version = [];
for ($x = 0; $x < $n ; $x++)
{
$str = getBetween( $array_search[$x], $start = "***", $end = "***");
$array_version[] = str_replace("rev_","", $str);
}
echo "<pre>";
print_r($array_version);
echo "</pre>";
echo " ******* " .max($array_version);
echo "<br><br>";
$datetime = date("d-m-Y_H:i:s");
$newfile = $filename ."_" .$datetime ."_" .$array[max($array_version)+1];
echo "Nouveau fichier " .$newfile;
copy($filename, $newfile);
}
}
function getBetween($string, $start = "", $end = "")
{
if (strpos($string, $start))
{
$startCharCount = strpos($string, $start) + strlen($start);
$firstSubStr = substr($string, $startCharCount, strlen($string));
$endCharCount = strpos($firstSubStr, $end);
if ($endCharCount == 0)
{
$endCharCount = strlen($firstSubStr);
}
return substr($firstSubStr, 0, $endCharCount);
}
else
{
return '';
}
}
function explore_folder($path)
{
$objects = is_readable($path) ? scandir($path) : array();
$folders = array();
$files = array();
if (is_array($objects))
{
foreach ($objects as $file)
{
if ($file == '.' || $file == '..')
{
continue;
}
$new_path = $path . '/' . $file;
if (is_file($new_path))
{
$files[] = $file;
}
elseif (is_dir($new_path) && $file != '.' && $file != '..')
{
$folders[] = $file;
}
}
}
return $files;
}
?>