PHP fpassthru() ວິທີການ
ການສະແດງ ແລະ ການນໍາໃຊ້
fpassthru() ຈະອ່ານບັດຕະວັດທັງໝົດທີ່ຍັງມີຢູ່ທີ່ຄູ່ມູນບັດຕະວັດ.
ຫນັງວິທີການນີ້ ຈະອ່ານບັດຕະວັດຈາກຈຸດປະຈັນເປັນຕອນທ້າຍ ແລະ ຂຽນຜົນຄະແນນຫຼັງຄືນໃນບ່ອນສະຕູສຽງອອກສຽງ.
ວິທີການ
fpassthru(file)
ພຽງພໍ | ອະທິບາຍ |
---|---|
file | ຄວາມຈໍາເປັນ. ກໍານົດບັດຕະວັດທີ່ຈະອ່ານ ບັດຕະວັດທີ່ໄດ້ເປີດ ຫຼື ອານຫາດ. |
ອະທິບາຍ
ຖ້າເກີດຂໍ້ບັນຫາ fpassthru() ຈະກັບຄືນ false. ບໍ່ດັ່ງນັ້ນ fpassthru() ຈະກັບຄືນຈາກ file ອ່ານ ແລະ ສົ່ງຕໍ່ຫາອອກສຽງຄຳມັນ.
ຄູ່ມູນແບບບັດຕະວັດຕ້ອງເປັນມາດຕະຖານ ແລະ ຕ້ອງທີ່ຍັງມີຢູ່ບາງຢ່າງ fopen() ຫາກ fsockopen() ໄດ້ເປີດ (ແຕ່ຍັງບໍ່ໄດ້ຖືກ fclose() of the file that is 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 search at a specific location, but just want to download the file content to the output buffer, you should use readfile(), this can save the fopen() call.
Comment:When using fpassthru() with 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 www server index page:
<?php $file = fopen("http://www.example.com","r"); fpassthru($file); ?>