PHP read files and can support remote file code sharing _php Tutorial

Source: Internet
Author: User
Tags fread php read file
PHP Read File

Case One
Copy CodeThe code is as follows:
$file = ' jb51.net.php ';
This case does not support remote
$fso = fopen ($file, ' R ');
echo $data = Fread ($fso, FileSize ($file));
Fclose ($FSO);
?>

fopen () binds the name resource specified by file to a stream.
FileSize returns the number of bytes in the file size if an error returns FALSE.
Note: Because PHP's integer type is signed, and most platforms use 32-bit integers, the filesize () function may return unintended results when it encounters a file larger than 2GB. For files between 2GB and 4GB, you can usually use sprintf ("%u", Filesi Ze ($file)) to overcome this problem.
Fread () reads up to length bytes from a file pointer handle. The function will stop reading a file when it is available, or (for a network stream) when it has been read by the length of bytes, or when it reaches EOF, depending on what kind of situation is encountered first.
Description: Low version usage! Recommended PHP5 with File_get_contents

Case Two
Copy CodeThe code is as follows:
$file = ' jb51.net.php ';
Support remote
$file = ' http://www.jb51.net ';//
echo $data = Implode (', File ($file));
?>

FILE--Reads the entire document into an array
Description
Read binary files

Case Three
Copy CodeThe code is as follows:
$file = ' http://www.jb51.net ';
Echo file_get_contents ($file);
?>

File_get_contents--Reads the entire file into a string
Description
String file_get_contents (string filename [, int use_include_path [, resource context]])
As with file (), the file is returned as a string except for file_get_contents ().
The file_get_contents () function is the preferred method for reading the contents of a file into a string. If operating system support also uses memory-mapping techniques to enhance performance.

http://www.bkjia.com/PHPjc/326101.html www.bkjia.com true http://www.bkjia.com/PHPjc/326101.html techarticle PHP Read file case a copy code code as follows: PHP $file = ' jb51.net.php ';//This case does not support remote $FSO = fopen ($file, ' R '); Echo $data = Fread ($fso, file Size ($file)); FCL ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.