aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorScott Dutton <scott@exussum.co.uk>2016-01-24 14:21:32 +0000
committerScott Dutton <scott@exussum.co.uk>2016-01-25 20:11:18 +0000
commit610048cc6d3e59297391b18493805057843a2aa4 (patch)
treeaeec96798881f787cc950dc4bb964d3609490312 /phpBB
parent67f3017274fdc749c9e5c75930dd15e3b1d0317d (diff)
downloadforums-610048cc6d3e59297391b18493805057843a2aa4.tar
forums-610048cc6d3e59297391b18493805057843a2aa4.tar.gz
forums-610048cc6d3e59297391b18493805057843a2aa4.tar.bz2
forums-610048cc6d3e59297391b18493805057843a2aa4.tar.xz
forums-610048cc6d3e59297391b18493805057843a2aa4.zip
[ticket/14431] Remote avatar uploading
Allow HTTPS images to be remotely uploaded. Also includes support for redirects (currently up to 5) PHPBB3-14431
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/includes/functions_upload.php31
1 files changed, 28 insertions, 3 deletions
diff --git a/phpBB/includes/functions_upload.php b/phpBB/includes/functions_upload.php
index 89bc31fa25..79f561c170 100644
--- a/phpBB/includes/functions_upload.php
+++ b/phpBB/includes/functions_upload.php
@@ -752,10 +752,11 @@ class fileupload
*
* @param string $upload_url URL pointing to file to upload, for example http://www.foobar.com/example.gif
* @param \phpbb\mimetype\guesser $mimetype_guesser Mimetype guesser
+ * @param int $redirect_count the current count of redirects
* @return object $file Object "filespec" is returned, all further operations can be done with this object
* @access public
*/
- function remote_upload($upload_url, \phpbb\mimetype\guesser $mimetype_guesser = null)
+ function remote_upload($upload_url, \phpbb\mimetype\guesser $mimetype_guesser = null, $redirect_count = 0)
{
global $user, $phpbb_root_path;
@@ -776,9 +777,18 @@ class fileupload
$url = parse_url($upload_url);
+ $default_port = 80;
+ $hostname = $url['host'];
+
+ if ($url['scheme'] == 'https')
+ {
+ $default_port = 443;
+ $hostname = 'tls://' . $url['host'];
+ }
+
$host = $url['host'];
$path = $url['path'];
- $port = (!empty($url['port'])) ? (int) $url['port'] : 80;
+ $port = (!empty($url['port'])) ? (int) $url['port'] : $default_port;
$upload_ary['type'] = 'application/octet-stream';
@@ -818,7 +828,7 @@ class fileupload
$errno = 0;
$errstr = '';
- if (!($fsock = @fsockopen($host, $port, $errno, $errstr)))
+ if (!($fsock = @fsockopen($hostname, $port, $errno, $errstr)))
{
$file = new fileerror($user->lang[$this->error_prefix . 'NOT_UPLOADED']);
return $file;
@@ -899,6 +909,21 @@ class fileupload
$file = new fileerror($user->lang[$this->error_prefix . 'URL_NOT_FOUND']);
return $file;
}
+ else if (stripos($line, 'location: ') !== false)
+ {
+ //there is a redirect, follow up to 5
+ if ($redirect_count >= 5)
+ {
+ $file = new fileerror($user->lang[$this->error_prefix . 'URL_NOT_FOUND']);
+ return $file;
+ }
+
+ $upload_url = rtrim(str_replace('location: ', '', strtolower($line)));
+ //close the current connection, lets not leave dangeling connections open
+ @fclose($fsock);
+
+ return $this->remote_upload($upload_url, $mimetype_guesser, ++$redirect_count);
+ }
}
}