Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

file_downloader.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 2.71 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb;
 015   
 016  class file_downloader
 017  {
 018      /** @var string Error string */
 019      protected $error_string = '';
 020   
 021      /** @var int Error number */
 022      protected $error_number = 0;
 023   
 024      /**
 025       * Retrieve contents from remotely stored file
 026       *
 027       * @param string    $host            File host
 028       * @param string    $directory        Directory file is in
 029       * @param string    $filename        Filename of file to retrieve
 030       * @param int        $port            Port to connect to; default: 80
 031       * @param int        $timeout        Connection timeout in seconds; default: 6
 032       *
 033       * @return mixed File data as string if file can be read and there is no
 034       *            timeout, false if there were errors or the connection timed out
 035       *
 036       * @throws \phpbb\exception\runtime_exception If data can't be retrieved and no error
 037       *        message is returned
 038       */
 039      public function get($host, $directory, $filename, $port = 80, $timeout = 6)
 040      {
 041          // Set default values for error variables
 042          $this->error_number = 0;
 043          $this->error_string = '';
 044   
 045          if ($socket = @fsockopen(($port == 443 ? 'tls://' : '') . $host, $port, $this->error_number, $this->error_string, $timeout))
 046          {
 047              @fputs($socket, "GET $directory/$filename HTTP/1.0\r\n");
 048              @fputs($socket, "HOST: $host\r\n");
 049              @fputs($socket, "Connection: close\r\n\r\n");
 050   
 051              $timer_stop = time() + $timeout;
 052              stream_set_timeout($socket, $timeout);
 053   
 054              $file_info = '';
 055              $get_info = false;
 056   
 057              while (!@feof($socket))
 058              {
 059                  if ($get_info)
 060                  {
 061                      $file_info .= @fread($socket, 1024);
 062                  }
 063                  else
 064                  {
 065                      $line = @fgets($socket, 1024);
 066                      if ($line == "\r\n")
 067                      {
 068                          $get_info = true;
 069                      }
 070                      else if (stripos($line, '404 not found') !== false)
 071                      {
 072                          throw new \phpbb\exception\runtime_exception('FILE_NOT_FOUND', array($filename));
 073                      }
 074                  }
 075   
 076                  $stream_meta_data = stream_get_meta_data($socket);
 077   
 078                  if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop)
 079                  {
 080                      throw new \phpbb\exception\runtime_exception('FSOCK_TIMEOUT');
 081                  }
 082              }
 083              @fclose($socket);
 084          }
 085          else
 086          {
 087              if ($this->error_string)
 088              {
 089                  $this->error_string = utf8_convert_message($this->error_string);
 090                  return false;
 091              }
 092              else
 093              {
 094                  throw new \phpbb\exception\runtime_exception('FSOCK_DISABLED');
 095              }
 096          }
 097   
 098          return $file_info;
 099      }
 100   
 101      /**
 102       * Get error string
 103       *
 104       * @return string Error string
 105       */
 106      public function get_error_string()
 107      {
 108          return $this->error_string;
 109      }
 110   
 111      /**
 112       * Get error number
 113       *
 114       * @return int Error number
 115       */
 116      public function get_error_number()
 117      {
 118          return $this->error_number;
 119      }
 120  }
 121