[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb; 15 16 class file_downloader 17 { 18 /** @var string Error string */ 19 protected $error_string = ''; 20 21 /** @var int Error number */ 22 protected $error_number = 0; 23 24 /** 25 * Retrieve contents from remotely stored file 26 * 27 * @param string $host File host 28 * @param string $directory Directory file is in 29 * @param string $filename Filename of file to retrieve 30 * @param int $port Port to connect to; default: 80 31 * @param int $timeout Connection timeout in seconds; default: 6 32 * 33 * @return mixed File data as string if file can be read and there is no 34 * timeout, false if there were errors or the connection timed out 35 * 36 * @throws \phpbb\exception\runtime_exception If data can't be retrieved and no error 37 * message is returned 38 */ 39 public function get($host, $directory, $filename, $port = 80, $timeout = 6) 40 { 41 // Set default values for error variables 42 $this->error_number = 0; 43 $this->error_string = ''; 44 45 if ($socket = @fsockopen(($port == 443 ? 'tls://' : '') . $host, $port, $this->error_number, $this->error_string, $timeout)) 46 { 47 @fputs($socket, "GET $directory/$filename HTTP/1.0\r\n"); 48 @fputs($socket, "HOST: $host\r\n"); 49 @fputs($socket, "Connection: close\r\n\r\n"); 50 51 $timer_stop = time() + $timeout; 52 stream_set_timeout($socket, $timeout); 53 54 $file_info = ''; 55 $get_info = false; 56 57 while (!@feof($socket)) 58 { 59 if ($get_info) 60 { 61 $file_info .= @fread($socket, 1024); 62 } 63 else 64 { 65 $line = @fgets($socket, 1024); 66 if ($line == "\r\n") 67 { 68 $get_info = true; 69 } 70 else if (stripos($line, '404 not found') !== false) 71 { 72 throw new \phpbb\exception\runtime_exception('FILE_NOT_FOUND', array($filename)); 73 } 74 } 75 76 $stream_meta_data = stream_get_meta_data($socket); 77 78 if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop) 79 { 80 throw new \phpbb\exception\runtime_exception('FSOCK_TIMEOUT'); 81 } 82 } 83 @fclose($socket); 84 } 85 else 86 { 87 if ($this->error_string) 88 { 89 $this->error_string = utf8_convert_message($this->error_string); 90 return false; 91 } 92 else 93 { 94 throw new \phpbb\exception\runtime_exception('FSOCK_DISABLED'); 95 } 96 } 97 98 return $file_info; 99 } 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |