123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- class WebRequestUpload {
- protected $request;
- protected $doesExist;
- protected $fileInfo;
-
- public function __construct( $request, $key ) {
- $this->request = $request;
- $this->doesExist = isset( $_FILES[$key] );
- if ( $this->doesExist ) {
- $this->fileInfo = $_FILES[$key];
- }
- }
-
- public function exists() {
- return $this->doesExist;
- }
-
- public function getName() {
- if ( !$this->exists() ) {
- return null;
- }
- global $wgContLang;
- $name = $this->fileInfo['name'];
-
-
- $name = Sanitizer::decodeCharReferences( $name );
- $name = $wgContLang->normalize( $name );
- wfDebug( __METHOD__ . ": {$this->fileInfo['name']} normalized to '$name'\n" );
- return $name;
- }
-
- public function getSize() {
- if ( !$this->exists() ) {
- return 0;
- }
- return $this->fileInfo['size'];
- }
-
- public function getTempName() {
- if ( !$this->exists() ) {
- return null;
- }
- return $this->fileInfo['tmp_name'];
- }
-
- public function getError() {
- if ( !$this->exists() ) {
- return 0;
- }
- return $this->fileInfo['error'];
- }
-
- public function isIniSizeOverflow() {
- if ( $this->getError() == UPLOAD_ERR_INI_SIZE ) {
-
- return true;
- }
- $contentLength = $this->request->getHeader( 'Content-Length' );
- $maxPostSize = wfShorthandToInteger(
- ini_get( 'post_max_size' ) ?: ini_get( 'hhvm.server.max_post_size' ),
- 0
- );
- if ( $maxPostSize && $contentLength > $maxPostSize ) {
-
- return true;
- }
- return false;
- }
- }
|