* @return string or NULL if no such file.
*/
public function getFileTempname( $key ) {
- $file = new WebRequestUpload( $key );
+ $file = new WebRequestUpload( $this, $key );
return $file->getTempName();
}
* @return integer
*/
public function getFileSize( $key ) {
- $file = new WebRequestUpload( $key );
+ $file = new WebRequestUpload( $this, $key );
return $file->getSize();
}
* @return integer
*/
public function getUploadError( $key ) {
- $file = new WebRequestUpload( $key );
+ $file = new WebRequestUpload( $this, $key );
return $file->getError();
}
* @return string or NULL if no such file.
*/
public function getFileName( $key ) {
- $file = new WebRequestUpload( $key );
+ $file = new WebRequestUpload( $this, $key );
return $file->getName();
}
* @return WebRequestUpload
*/
public function getUpload( $key ) {
- return new WebRequestUpload( $key );
+ return new WebRequestUpload( $this, $key );
}
/**
}
} else {
$name = 'HTTP_' . str_replace( '-', '_', $name );
+ if ( $name === 'HTTP_CONTENT_LENGTH' && !isset( $_SERVER[$name] ) ) {
+ $name = 'CONTENT_LENGTH';
+ }
if ( isset( $_SERVER[$name] ) ) {
return $_SERVER[$name];
} else {
* Object to access the $_FILES array
*/
class WebRequestUpload {
+ protected $request;
protected $doesExist;
protected $fileInfo;
/**
* Constructor. Should only be called by WebRequest
*
+ * @param $request WebRequest The associated request
* @param $key string Key in $_FILES array (name of form field)
*/
- public function __construct( $key ) {
+ public function __construct( $request, $key ) {
+ $this->request = $request;
$this->doesExist = isset( $_FILES[$key] );
if ( $this->doesExist ) {
$this->fileInfo = $_FILES[$key];
return $this->fileInfo['error'];
}
+
+ /**
+ * Returns whether this upload failed because of overflow of a maximum set
+ * in php.ini
+ *
+ * @return bool
+ */
+ public function isIniSizeOverflow() {
+ if ( $this->getError() == UPLOAD_ERR_INI_SIZE ) {
+ # PHP indicated that upload_max_filesize is exceeded
+ return true;
+ }
+
+ $contentLength = $this->request->getHeader( 'CONTENT_LENGTH' );
+ if ( $contentLength > wfShorthandToInteger( ini_get( 'post_max_size' ) ) ) {
+ # post_max_size is exceeded
+ return true;
+ }
+
+ return false;
+ }
}
/**
# Check for a post_max_size or upload_max_size overflow, so that a
# proper error can be shown to the user
if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
- # Using the Content-length header is not an absolutely fail-safe
- # method, but the only available option. Otherwise broken uploads
- # will be handled by the parent method and return empty-file
- $contentLength = intval( $_SERVER['CONTENT_LENGTH'] );
- $maxPostSize = wfShorthandToInteger( ini_get( 'post_max_size' ) );
- if ( $this->mWebUpload->getError() == UPLOAD_ERR_INI_SIZE
- || $contentLength > $maxPostSize ) {
-
+ if ( $this->mWebUpload->isIniSizeOverflow() ) {
global $wgMaxUploadSize;
return array(
'status' => self::FILE_TOO_LARGE,
'max' => min(
$wgMaxUploadSize,
wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
- $maxPostSize
+ wfShorthandToInteger( ini_get( 'post_max_size' ) )
),
);
}