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.
⇒ Writing a String to a File with a File Handle in PHP
⇐ Issue with "while ($c=fgetc($f))" Loop in PHP
2024-01-04, ≈13🔥, 1💬
Popular Posts:
What is the "__init__()" class method? The "__init__()" class method is a special method that will b...
How to view API details on the Publisher Dashboard of an Azure API Management Service? You can follo...
What Is session_register() in PHP? session_register() is old function that registers global variable...
Can Two Forms Be Nested? Can two forms be nested? The answer is no and yes: No. You can not nest two...
How to use "link" command tool to link objet files? If you have object files previously compiled by ...