File "debug_upload01.php"

Full Path: /home/analogde/www/Prog/File explorer/debug_upload01.php
File size: 3.57 KB
MIME-type: text/x-php
Charset: utf-8

<?php

if (isset($_POST['submit']))
{
/*
    $upload_location = "/home/analogde/www/Administratif/CAF/";
    $upload_location = "/home/analogde/www/Fusion/File explorer/";
    $filename = "accent.php";

    $path = $upload_location.$filename;


    $pos = strrpos($filename,'.');
    echo $pos ."<br>";
    $ext = substr($filename,$pos); 
    echo $ext ."<br>";
    $file_basename = substr($filename, 0, strripos($filename, '.')); 
    echo $file_basename ."<br>";
    
    

    $array_version = [];
    for ($x = 0; $x <= 1000; $x++) 
    {
      $array[] = "***rev_" .$x ."***"; 
    }

    $arrFiles = scandir($upload_location);

    //print_r($arrFiles);

    $findFiles = [];

    for ($x = 0; $x < count($arrFiles); $x++)
    {
        //echo "---->>>>: " .$arrFiles[$x] ."<br>";

        if(strpos( $arrFiles[$x], $filename) !== false)
        {
            //echo "Found  " .$arrFiles[$x] ."<br>";
            $findFiles[] = $arrFiles[$x];
        }
    }

    echo "<pre>";
    print_r($findFiles);
    echo "</pre>";
    
    $array_version = [];    

    echo "NB fichiers detectés " .count($findFiles) ."<br>";

    if( count($findFiles) == 0)
    {
        echo "Origine " ."<br>";
    }
    else if( count($findFiles) == 1)
    {
        $datetime = date("d-m-Y_H:i:s");  
        $path = $upload_location .$file_basename ."_" .$datetime ."_" ."***rev_1***" .$ext;
        echo " :::::: " .$path ."<br>";        
       
    }
    else
    {
        echo "Revisions trouvées " ."<br>";

        for ($x = 0; $x < count($findFiles) ; $x++) 
        {
            $str = getBetween( $findFiles[$x], $start = "***", $end = "***");
            if( strlen($str) != 0)
            {
                $array_version[] = str_replace("rev_","", $str);
            }
        }

        echo "<pre>";
        print_r($array_version);
        echo "</pre>";
        $max_indice = max($array_version);
        $max_indice = $max_indice + 1;
        echo " Nouvel indice " .$max_indice ."<br>";
        //accent.php_15-06-2024_18:34:19_***rev_4***
        $datetime = date("d-m-Y_H:i:s");  
        $path = $upload_location .$file_basename ."_" .$datetime ."_" ."***rev_" .$max_indice ."***" .$ext;
        echo ">>>>>> " .$path ."<br>";
    }
*/
}


  

/************************************************************************************************/
    /*function upload()
    {


    }*/
/************************************************************************************************/
    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 '';
        }
    }    
?>

<!DOCTYPE html>
<html>

<body>
    <!--
    <form action="" method="post" enctype="multipart/form-data">
        Upload File: <input type="file" name="user_file" required />
        <input type="submit" name="submit">
    </form>
    -->
    <form method='post' action='' enctype="multipart/form-data">
    Upload File: <input type="file" id='files' name="files[]" multiple><br>
    <input type="button" id="submit" value='Upload'>
</form>


</body>



</html>