Binary-safe file read in PHP

Description

The following code shows how to binary-safe file read.

Example


//from w w w .j a  va2  s .c  om

<?php
// For PHP 5 and up
$handle = fopen("http://www.java2s.com/", "rb");
$contents = stream_get_contents($handle);
fclose($handle);
//OR
$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
  $contents .= fread($handle, 8192);
}
fclose($handle);
?>




















Home »
  PHP Tutorial »
    File »




Directory
DirectoryIterator
Drive
File
File Permission
File Read Save
FileSystemIterator
Path
Zip