Work frequently with PHP to manipulate files, so the common file operations to sort out:
1 classhylaz_file{2 /**3 * Read File4 * @param string $pathname5 * @return String content6 */7 Public Static functionRead_file ($pathname){8 return@file_get_contents($pathname);9 }Ten /** One * Write File A * @param string $pathname file name - * @param string $data The data written to the file - * @param string $MD Open File mode the * @return int bool - */ - Public Static functionWrite_file ($pathname,$data,$MD= ' WB '){ - if(!$fp=fopen($pathname,$mode)) + return false; - Flock($fp,lock_ex); + for($result=$written=0,$length=strlen($data),$written<$length;$written+=$result){ A if(($result=fwrite($fp,substr($data,$written)))===FALSE){ at Break; - } - } - Flock($fp,lock_un); - fclose($fp); - return Is_int($result); in } -}
1 classhylaz_file{2 /**3 * Read File4 * @param string $pathname5 * @return String content6 */7 Public Static functionRead_file ($pathname){8 return@file_get_contents($pathname);9 }Ten /** One * Write File A * @param string $pathname file name - * @param string $data The data written to the file - * @param string $MD Open File mode the * @return int bool - */ - Public Static functionWrite_file ($pathname,$data,$MD= ' WB '){ - if(!$fp=fopen($pathname,$mode)) + return false; - Flock($fp,lock_ex); + for($result=$written=0,$length=strlen($data),$written<$length;$written+=$result){ A if(($result=fwrite($fp,substr($data,$written)))===FALSE){ at Break; - } - } - Flock($fp,lock_un); - fclose($fp); - return Is_int($result); in } -}
PHP Common class Libraries-file operations classes