Commit 4607eaa0adbd5be76b63d1ac421aca5a0fe2812d
1 parent
8e283c24
Exists in
master
and in
110 other branches
Add proxy support in upload script
Showing
1 changed file
with
34 additions
and
3 deletions
Show diff stats
php/uploadFile.php
... | ... | @@ -39,6 +39,13 @@ |
39 | 39 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
40 | 40 | curl_setopt($ch, CURLOPT_HEADER, true); |
41 | 41 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
42 | + // BRE - Add proxy host if exists | |
43 | + if (defined('HTTP_PROXY_HOST')) { | |
44 | + curl_setopt($ch, CURLOPT_PROXY, "http://".HTTP_PROXY_HOST); | |
45 | + if (defined('HTTP_PROXY_USER')) { | |
46 | + curl_setopt($ch, CURLOPT_PROXYUSERPWD, HTTP_PROXY_USER); | |
47 | + } | |
48 | + } | |
42 | 49 | $data = curl_exec($ch); |
43 | 50 | curl_close($ch); |
44 | 51 | |
... | ... | @@ -166,12 +173,12 @@ |
166 | 173 | die(json_encode($response)); |
167 | 174 | } |
168 | 175 | |
169 | - if ($file['size'] > DISK_QUOTA) | |
176 | + if (isset($file['size']) && ($file['size'] > DISK_QUOTA)) | |
170 | 177 | { |
171 | 178 | $response = array( 'success' => false, 'error' => 'The file you selected is too big for allowed disk quota'); |
172 | 179 | die(json_encode($response)); |
173 | 180 | } |
174 | - | |
181 | + | |
175 | 182 | if ($wsMgr->getWsSize() + $fileSize > DISK_QUOTA && $isFile) |
176 | 183 | { |
177 | 184 | $response = array( 'success' => false, 'error' => 'Please clean up you workspace. You are about to exceed available disk space'); |
... | ... | @@ -185,7 +192,31 @@ |
185 | 192 | die(json_encode($response)); |
186 | 193 | } |
187 | 194 | |
188 | - if (!copy($remoteName, $localName)) | |
195 | + | |
196 | + // BRE - Add proxy host if exists | |
197 | + $result = FALSE; | |
198 | + if (defined('HTTP_PROXY_HOST')) { | |
199 | + $options = array( | |
200 | + 'http' => array( | |
201 | + 'method' => 'GET', | |
202 | + 'timeout' => '5', | |
203 | + 'user_agent' => 'PHP libxml agent', | |
204 | + 'ignore_errors' => true, | |
205 | + ) | |
206 | + ); | |
207 | + $options['http']['proxy'] = 'tcp://'.HTTP_PROXY_HOST; | |
208 | + $options['http']['request_fulluri'] = TRUE; | |
209 | + if (defined('HTTP_PROXY_USER')) { | |
210 | + $options['http']['header'] = "Proxy-Authorization: Basic ".base64_encode(HTTP_PROXY_USER); | |
211 | + } | |
212 | + $context = stream_context_create($options); | |
213 | + $result = copy($remoteName, $localName, $context); | |
214 | + } | |
215 | + else { | |
216 | + $result = copy($remoteName, $localName); | |
217 | + } | |
218 | + | |
219 | + if (!$result) | |
189 | 220 | { |
190 | 221 | $response = array( 'success' => false, 'error' => 'Can\'t copy '.$fileName); |
191 | 222 | die(json_encode($response)); |
... | ... |