PHP: Vérifier si on a attends la fin du fichier

 
<?
    $huge_file = fopen("VERY_BIG_FILE.txt", "r");
    while (!feof($huge_file)) {
            print fread($huge_file, 1024);
    }
    fclose($huge_file);
?>
  
  

PHP: Afficher la taille d’un fichier en octet

<html>
<head>
<title>Get the file size: filesize</title>
</head>
<body>
<?php
$file = "test.txt";
outputFileTestInfo( $file );
function outputFileTestInfo( $f ){
   if ( ! file_exists( $f ) ){
       print "$f does not exist<BR>";
      return;
   }
   print "$f is ".(filesize($f))." bytes<br>";
}
?>
</body>
</html>
           
       

PHP: Trouver la taille d’un fichier

<?php
  $myfile = "./test.txt";
  if (file_exists ($myfile)) {
    $checksize=filesize ($myfile);
    echo "$checksize";
  } else {
    echo "The file doesn't exist!";
  }
?>
           
       

PHP: Compter le nombre de paragraphe d’un fichier

 
<?php
$paragraphs = 0;
if ($fh = fopen('great-american-novel.txt','r')) {
  while (! feof($fh)) {
    $s = fgets($fh);
    if ((" " == $s) || (" " == $s)) {
      $paragraphs++;
    }
  }
}
print $paragraphs;
?>
  
  

PHP: Copier un fichier

<?php
   $source = "./test.txt";
   $destination = "./copy.txt";
                
   if(copy($source, $destination)) {
      echo "File copied successfully.", " ";
   } else {
      echo "The specified file could not be copied. Please try again.", " ";
   }
               
?>
           
       

PHP: Fonction de base pour lire un fichier compressé

 
<?php
$fh = fopen('compress.zlib://file.gz','r') or die("can't open: $php_errormsg");
while ($line = fgets($fh)) {
    // $line is the next line of uncompressed data
}
fclose($fh) or die("can't close: $php_errormsg");
?>
  
  

PHP: Ouvrir un fichier et lire son contenu

 
<?
$fh = fopen('data.txt','rb');
if (! $fh) {
    print "Error opening people.txt: $php_errormsg";
} else {
    for ($line = fgets($fh); ! feof($fh); $line = fgets($fh)) {
        if ($line === false) {
            print "Error reading line: $php_errormsg";
        } else {
            $line = trim($line);
            $info = explode('|', $line);
            print '<li><a href="mailto:' . $info[0] . '">' . $info[1] ."</li> ";
        }
    }
    if (! fclose($fh)) {
        print "Error closing people.txt: $php_errormsg";
    }
}
?>
//data.txt
a@example.com|Alice
b@example.org|Bill
c@example.com|Charlie
d@example.com|Lewis
  
  

PHP: Classe personalisé pour traiter un fichier

 of constants for ease of use. 
    const FOUNDERROR = "Sorry, the file in question does not exist."; 
    const PERMERROR = "Sorry, you do not have the proper