@@ -113,7 +113,6 @@ public function getFileSize($filename) {
113113 * null on failure.
114114 */
115115 public function getFileSizeViaCurl ($ fileName ) {
116- global $ fileSizeFromContentLength ;
117116 if (\OC ::$ server ->getIniWrapper ()->getString ('open_basedir ' ) === '' ) {
118117 $ pathParts = \explode ('/ ' , $ fileName );
119118 $ encodedPathParts = \array_map ('rawurlencode ' , $ pathParts );
@@ -131,7 +130,14 @@ public function getFileSizeViaCurl($fileName) {
131130 // that curl_exec processes internally. That is working, and so we use that as
132131 // an alternative way to access Content-Length.
133132 \curl_setopt ($ ch , CURLOPT_HEADER , true );
134- \curl_setopt ($ ch , CURLOPT_HEADERFUNCTION , ['OC\LargeFileHelper ' , 'curlHeaderCallback ' ]);
133+ $ fileSizeFromContentLength = -1 ;
134+ \curl_setopt ($ ch , CURLOPT_HEADERFUNCTION , function ($ ch , $ header_line ) use (&$ fileSizeFromContentLength ) {
135+ \preg_match ('/Content-Length: (\d+)/ ' , $ header_line , $ matches );
136+ if (isset ($ matches [1 ])) {
137+ $ fileSizeFromContentLength = 0 + $ matches [1 ];
138+ }
139+ return \strlen ($ header_line );
140+ });
135141 $ data = \curl_exec ($ ch );
136142 \curl_close ($ ch );
137143 if ($ data !== false ) {
@@ -140,23 +146,17 @@ public function getFileSizeViaCurl($fileName) {
140146 if (isset ($ matches [1 ])) {
141147 return 0 + $ matches [1 ];
142148 }
143- if (isset ($ fileSizeFromContentLength )) {
149+ // If the CURLOPT_HEADERFUNCTION detected a Content-Length
150+ // then it should have set $fileSizeFromContentLength to
151+ // something greater than or equal to zero. If so, return it.
152+ if ($ fileSizeFromContentLength >= 0 ) {
144153 return $ fileSizeFromContentLength ;
145154 }
146155 }
147156 }
148157 return null ;
149158 }
150159
151- public static function curlHeaderCallback ($ ch , $ header_line ) {
152- global $ fileSizeFromContentLength ;
153- \preg_match ('/Content-Length: (\d+)/ ' , $ header_line , $ matches );
154- if (isset ($ matches [1 ])) {
155- $ fileSizeFromContentLength = 0 + $ matches [1 ];
156- }
157- return \strlen ($ header_line );
158- }
159-
160160 /**
161161 * @brief Tries to get the size of a file via an exec() call.
162162 *
0 commit comments