PHP - Fonction stat ()

La fonction stat () peut renvoyer les informations sur un fichier.

Syntaxe

array stat ( string $filename )

Cette fonction peut rassembler les statistiques du fichier nommé par nom de fichier. Si le nom de fichier est un lien symbolique, les statistiques proviennent du fichier lui-même et non du lien symbolique. La fonction lstat () est identique à la fonction stat (), sauf qu'elle pourrait à la place être basée sur l'état des liens symboliques.

Exemple 1

<?php
   $stat = stat("/PhpProject/sample.txt");  // Get file stat 

   echo "Acces time: " .$stat["atime"];    // Print file access time, this is the same as calling fileatime()  
   echo "\nModification time: " .$stat["mtime"];  //Print file modification time, this is the same as calling filemtime()
   echo "\nDevice number: " .$stat["dev"];  //  Print the device number
?>

Production

Acces time: 1590217956
Modification time: 1591617832
Device number: 1245376677

Exemple-2

<?php
   $stat = stat("/PhpProject/sample.txt");
   
   if(!$stat) {
      echo "stat() call failed...";
   } else {
      $atime = $stat["atime"] + 604800;

   if(!touch("/PhpProject1/sampl2.txt", time(), $atime)) {
      echo "failed to touch file...";
   } else {
      echo "touch() returned success...";
   }
?>

Production

touch() returned success...