توابع fpassthru() PHP

تعریف و استفاده

آزاد کردن fpassthru() همه داده‌های باقی‌مانده در فایل‌نما.

این تابع فایل‌نمای داده شده را از موقعیت فعلی تا EOF می‌خواند و نتایج را به حافظه پشتیبان خروجی می‌نویسد.

جمله‌بندی

fpassthru(file)
پارامترها توضیحات
file ضروری. مشخص می‌کند فایل یا منابع باز شده‌ای که باید خوانده شود.

توضیحات

در صورت بروز خطا، fpassthru() false را برمی‌گرداند. در غیر این صورت file خوانده و به عنوان تعداد کاراکترهای ارسالی

پایان نامه باید معتبر باشد و باید به یک فایل fopen() یا fsockopen() با موفقیت باز شد (اما هنوز به fclose() the file closed)。

Tips and Comments

Tip:If you have already written data to the file, you must call rewind() to move the file pointer to the beginning of the file.

Tip:If you do not modify the file or retrieve at a specific location, but just want to download the content of the file to the output buffer, you should use readfile(), this can save the fopen() call.

Comments:When using fpassthru() for binary files on Windows systems, make sure to add b to the mode when opening the file with fopen() to open the file in binary mode. It is encouraged to use the b flag when handling binary files, even if the system does not need it, so that the script has better portability.

Instance

Example 1

<?php
$file = fopen("test.txt","r");
// Read the first line
fgets($file);
// Send the rest of the file to the output buffer
echo fpassthru($file);
fclose($file);
?>

Output:

There are three lines in this file.
This is the last line.59

Note:59 indicates the number of characters passed.

Example 2

Dump the index page of the www server:

<?php
$file = fopen("http://www.example.com","r");
fpassthru($file);
?>