Introduction: Read and write large "binary" files, do not need to apply very large memory (fopen, Fread, fwrite, fclose)! To reduce revenue and increase speed!
Tell yourself once a day, "I'm really good" ....
Speed reading and writing large files, in the actual work process in fact, it must be a lot of people have this experience-you know, if you use Notepad (Notepad) to open 10M text file, it will be stuck to no response, but if you use sublime or notepad++ to open instantly.
Do not expand the talk, the interface is simple, many say useless, directly on the code.
Function
<?PHP/** Read and write the sophomore file, do not need to request a lot of memory * only read the content to create the file * Guaranteed directory writable * @param string $srcPath source file path * @param string $dstPath destination file path * @return BOOL*/functionFetch_big_file ($srcPath,$dstPath) { //set script execution time to be infinitely long Set_time_limit(0); if(!$FPSRC=fopen($srcPath, "RB")) { return false; } //Write file-is it open? $isWriteFileOpen=false; Do { //8*1024 bytes per read $data=fread($FPSRC, 8192); if(!$data) { Break; } Else if(!$isWriteFileOpen) { //The first time the file is read and there is content to create the file $fpDst=fopen($dstPath, "WB"); $isWriteFileOpen=true; fwrite($fpDst,$data); } Else { //Write fwrite($fpDst,$data); } } while(true); fclose($FPSRC); fclose($fpDst); return true;}//examples of features:$srcPath= ' D:/php/data/eclipse-jee-kepler-r-win32-x86_64.pdf ';$dstPath= ' Z:/reslibcovertingfiles/eclipse-jee-kepler-r-win32-x86_64.pdf '; Fetch_big_file ($srcPath,$dstPath);Echo' Success ';
Crossing, if you are wrong, please point it out!
To be continued .....
This site article is for baby bus SD. Team Original, reproduced must be clearly noted: (the author's official website: Baby bus )
Reprinted from "Baby bus Superdo Team" original link: http://www.cnblogs.com/superdo/p/4794186.html
[PHP Learning Tutorial]003. High-speed read and write big data "binary" file, do not need to request large memory (Byte Block)