Tools, FAQ, Tutorials:
Reading a File in Binary Mode in PHP
How To Read a File in Binary Mode in PHP?
✍: FYIcenter.com
If you have a file that stores binary data, like an executable program or picture file, you need to read the file in binary mode to ensure that none of the data gets modified during the reading process. You need to:
Here is a PHP script example on reading binary file:
<?php $in = fopen("/windows/system32/ping.exe", "rb"); $out = fopen("/temp/myPing.exe", "w"); $count = 0; while (!feof($in)) { $count++; $buffer = fread($in,64); fwrite($out,$buffer); } fclose($out); fclose($in); print("About ".($count*64)." bytes read.\n"); ?>
This script will print:
About 16448 bytes read.
This script actually copied an executable program file ping.exe in binary mode to new file. The new file should still be executable. Try it: \temp\myping dev.fyicenter.com.
Â
⇒Reading and Writing Files in PHP
⇒⇒PHP Tutorials
2016-11-27, 1427👍, 0💬
Popular Posts:
Where to find tutorials on EPUB file format? I want to know how to create EPUB books. Here is a larg...
How To Add Column Headers to a Table? If you want to add column headers to a table, you need to use ...
What is test testing area for? The testing area is provided to allow visitors to post testing commen...
How to Create a New Instance of a Class? There are two ways to create a new instance (object) of a c...
How to include additional claims in Azure AD v2.0 id_tokens? If you want to include additional claim...