XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
Download.php
Go to the documentation of this file.
1 <?php
2 
8 class HTTP_Request2_Observer_Download implements SplObserver
9 {
10  protected $filename;
11  protected $fp;
12 
13  public function __construct($filename)
14  {
15  $this->filename = $filename;
16  }
17 
18  public function update(SplSubject $subject)
19  {
20  $event = $subject->getLastEvent();
21 
22  switch($event['name'])
23  {
24  case 'receivedHeaders':
25  $this->fp = @fopen($this->filename, 'wb');
26  if(!$this->fp)
27  {
28  throw new Exception("Cannot open target file '{$filename}'");
29  }
30  break;
31 
32  case 'receivedBodyPart':
33  case 'receivedEncodedBodyPart':
34  fwrite($this->fp, $event['data']);
35  break;
36 
37  case 'receivedBody':
38  fclose($this->fp);
39  }
40  }
41 }
update(SplSubject $subject)
Definition: Download.php:18