| @@ 85-106 (lines=22) @@ | ||
| 82 | * @param string $mode fopen() mode (default: 'wb') |
|
| 83 | * @return bool |
|
| 84 | */ |
|
| 85 | function write_file($path, $data, $mode = 'wb') |
|
| 86 | { |
|
| 87 | if ( ! $fp = @fopen($path, $mode)) |
|
| 88 | { |
|
| 89 | return FALSE; |
|
| 90 | } |
|
| 91 | ||
| 92 | flock($fp, LOCK_EX); |
|
| 93 | ||
| 94 | for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result) |
|
| 95 | { |
|
| 96 | if (($result = fwrite($fp, substr($data, $written))) === FALSE) |
|
| 97 | { |
|
| 98 | break; |
|
| 99 | } |
|
| 100 | } |
|
| 101 | ||
| 102 | flock($fp, LOCK_UN); |
|
| 103 | fclose($fp); |
|
| 104 | ||
| 105 | return is_int($result); |
|
| 106 | } |
|
| 107 | } |
|
| 108 | ||
| 109 | // ------------------------------------------------------------------------ |
|
| @@ 419-440 (lines=22) @@ | ||
| 416 | * @param string $filepath the file name |
|
| 417 | * @return bool |
|
| 418 | */ |
|
| 419 | public function archive($filepath) |
|
| 420 | { |
|
| 421 | if ( ! ($fp = @fopen($filepath, 'w+b'))) |
|
| 422 | { |
|
| 423 | return FALSE; |
|
| 424 | } |
|
| 425 | ||
| 426 | flock($fp, LOCK_EX); |
|
| 427 | ||
| 428 | for ($result = $written = 0, $data = $this->get_zip(), $length = strlen($data); $written < $length; $written += $result) |
|
| 429 | { |
|
| 430 | if (($result = fwrite($fp, substr($data, $written))) === FALSE) |
|
| 431 | { |
|
| 432 | break; |
|
| 433 | } |
|
| 434 | } |
|
| 435 | ||
| 436 | flock($fp, LOCK_UN); |
|
| 437 | fclose($fp); |
|
| 438 | ||
| 439 | return is_int($result); |
|
| 440 | } |
|
| 441 | ||
| 442 | // -------------------------------------------------------------------- |
|
| 443 | ||