MediaWiki  master
UploadFromFile.php
Go to the documentation of this file.
1 <?php
25 
32 class UploadFromFile extends UploadBase {
36  protected $mUpload = null;
37 
41  public function initializeFromRequest( &$request ) {
42  $upload = $request->getUpload( 'wpUploadFile' );
43  $desiredDestName = $request->getText( 'wpDestFile' );
44  if ( !$desiredDestName ) {
45  $desiredDestName = $upload->getName();
46  }
47 
48  // @phan-suppress-next-line PhanTypeMismatchArgumentNullable getName only null on failure
49  $this->initialize( $desiredDestName, $upload );
50  }
51 
57  public function initialize( $name, $webRequestUpload ) {
58  $this->mUpload = $webRequestUpload;
59  $this->initializePathInfo( $name,
60  $this->mUpload->getTempName(), $this->mUpload->getSize() );
61  }
62 
67  public static function isValidRequest( $request ) {
68  # Allow all requests, even if no file is present, so that an error
69  # because a post_max_size or upload_max_filesize overflow
70  return true;
71  }
72 
76  public function getSourceType() {
77  return 'file';
78  }
79 
83  public function verifyUpload() {
84  # Check for a post_max_size or upload_max_size overflow, so that a
85  # proper error can be shown to the user
86  if ( $this->mTempPath === null || $this->isEmptyFile() ) {
87  if ( $this->mUpload->isIniSizeOverflow() ) {
88  return [
89  'status' => UploadBase::FILE_TOO_LARGE,
90  'max' => min(
91  self::getMaxUploadSize( $this->getSourceType() ),
92  self::getMaxPhpUploadSize()
93  ),
94  ];
95  }
96  }
97 
98  return parent::verifyUpload();
99  }
100 }
Object to access the $_FILES array.
UploadBase and subclasses are the backend of MediaWiki's file uploads.
Definition: UploadBase.php:49
isEmptyFile()
Return true if the file is empty.
Definition: UploadBase.php:311
initializePathInfo( $name, $tempPath, $fileSize, $removeTempFile=false)
Definition: UploadBase.php:264
const FILE_TOO_LARGE
Definition: UploadBase.php:115
Implements regular file uploads.
initialize( $name, $webRequestUpload)
Initialize from a filename and a MediaWiki\Request\WebRequestUpload.
static isValidRequest( $request)
WebRequestUpload $mUpload
initializeFromRequest(&$request)