Site Tools


php_file

Read File

Весь файл одной строкой:

var_dump(file_get_contents("/tmp/V45NcnhCU2"));

Каждая строка как элемент массива

$fileArray = file("/var/log/asterisk/queue_log_for_test");
var_dump($fileArray);

Вывод содержимого файла на stdin

<?php
$file = 'monkey.gif';

if (file_exists($file)) {
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename='.basename($file));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate');
  header('Pragma: public');
  header('Content-Length: ' . filesize($file));
  ob_clean();
  flush();
  readfile($file);
  exit;
}

Write File

file_put_contents("/tmp/V45NcnhCU2", print_r($message, 1), FILE_APPEND);
$FileHandle = fopen("/home/u/user/user.ru/var.log","a");
fwrite($FileHandle, "VVV ===== " . date('Y-m-d H:i:s',time()) ." ===== VVV\n");
fwrite($FileHandle, "url: http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]\n");
fwrite($FileHandle, "request:");
fwrite($FileHandle, var_export($_REQUEST, true));
fwrite($FileHandle, "\nget:");
fwrite($FileHandle, var_export($_GET, true));
fwrite($FileHandle, "\npost:");
fwrite($FileHandle, var_export($_POST, true));
fwrite($FileHandle, "\ncookie:");
fwrite($FileHandle, var_export($_COOKIE, true));
...
fwrite($FileHandle, "\nsendHeaders:");
fwrite($FileHandle, var_export(headers_list(), true));

glob

Поиск файла по маске

array glob ( string $pattern [, int $flags = 0 ] )
foreach (glob("/home/system/phone/201310300000-380445690000-*.mp3") as $filename) {
    echo "$filename size" . filesize($filename) . "\n"; }

Список файлов в папке

      $arrayFiles = scandir($path);
      foreach ($arrayFiles as $key => $file){
          if(!in_array($file,array(".",".."))){
              ...do some
          }
      }
You could leave a comment if you were logged in.
php_file.txt · Last modified: 2019/10/19 17:38 (external edit)

Page Tools