static function CopyFile($from_file,$to_file,&$error = null,&$error_str = null){
		$bytes = 0;
		$error = false;
		$error_str = "";

		settype($from_file,"string");
		settype($to_file,"string");
		
		$in = fopen($from_file,"r");
		if(!$in){
			$error = true;
			$error_str = "can't open input file for reading";
			return $bytes;
		}
		$__target_file_exists = false;
		if(file_exists($to_file)){
			$__target_file_exists = true;
		}
		$out = fopen($to_file,"w");
		if(!$out){
			$error = true;
			$error_str = "can't open output file for writing";
			return $bytes;
		}

		$buffer = "";
		while(!feof($in) && $in){
			$buffer = fread($in,4096);
			fwrite($out,$buffer,strlen($buffer));
			$bytes += strlen($buffer);
		}

		
		fclose($in);
		fclose($out);
		
		//menit modsouboru, jenom, kdyz soubor drive neexistoval
		if(!$__target_file_exists){
			$_old_umask = umask(0);
			$_stat = chmod($to_file,0666);
			umask($_old_umask);

			if(!$_stat && $error==false){
				$error = true;
				$error_str = "failed to do chmod on $to_file";
				return $bytes;
			}
		}

		return $bytes;
	}
static function CopyFile($from_file,$to_file,&$error = null,&$error_str = null){
		$bytes = 0;
		$error = false;
		$error_str = "";

		settype($from_file,"string");
		settype($to_file,"string");
		
		$in = fopen($from_file,"r");
		if(!$in){
			$error = true;
			$error_str = "can't open input file for reading";
			return $bytes;
		}
		$__target_file_exists = false;
		if(file_exists($to_file)){
			$__target_file_exists = true;
		}
		$out = fopen($to_file,"w");
		if(!$out){
			$error = true;
			$error_str = "can't open output file for writing";
			return $bytes;
		}

		$buffer = "";
		while(!feof($in) && $in){
			$buffer = fread($in,4096);
			fwrite($out,$buffer,strlen($buffer));
			$bytes += strlen($buffer);
		}

		
		fclose($in);
		fclose($out);
		
		//menit modsouboru, jenom, kdyz soubor drive neexistoval
		if(!$__target_file_exists){
			$_old_umask = umask(0);
			$_stat = chmod($to_file,0666);
			umask($_old_umask);

			if(!$_stat && $error==false){
				$error = true;
				$error_str = "failed to do chmod on $to_file";
				return $bytes;
			}
		}

		return $bytes;
	}
static function CopyFile ( $ from_file , $ to_file , & $ error = null , & $ error_str = null ) { $ bytes = 0 ; $ error = false ; $ error_str = "" ; settype ( $ from_file , "string" ) ; settype ( $ to_file , "string" ) ; $ in = fopen ( $ from_file , "r" ) ; if ( ! $ in ) { $ error = true ; $ error_str = "can't open input file for reading" ; return $ bytes ; } $ __target_file_exists = false ; if ( file_exists ( $ to_file ) ) { $ __target_file_exists = true ; } $ out = fopen ( $ to_file , "w" ) ; if ( ! $ out ) { $ error = true ; $ error_str = "can't open output file for writing" ; return $ bytes ; } $ buffer = "" ; while ( ! feof ( $ in ) && $ in ) { $ buffer = fread ( $ in , 4096 ) ; fwrite ( $ out , $ buffer , strlen ( $ buffer ) ) ; $ bytes += strlen ( $ buffer ) ; } fclose ( $ in ) ; fclose ( $ out ) ; //menit modsouboru, jenom, kdyz soubor drive neexistoval if ( ! $ __target_file_exists ) { $ _old_umask = umask ( 0 ) ; $ _stat = chmod ( $ to_file , 0666 ) ; umask ( $ _old_umask ) ; if ( ! $ _stat && $ error == false ) { $ error = true ; $ error_str = "failed to do chmod on $to_file" ; return $ bytes ; } } return $ bytes ; }
Creates a copy of a file.

When the target file does not exist, it is created with permissions 0666.

@param string $from_file Source file
@param string $to_file Target file
@param boolean &$error Error flag
@param string &$error_str Error message
@return int Number of copied bytes
Creates a copy of a file .