(bug 23380) Uploaded files that are larger than allowed by PHP now show a useful...
[lhc/web/wiklou.git] / includes / upload / UploadFromFile.php
1 <?php
2 /**
3 * @file
4 * @ingroup upload
5 *
6 * @author Bryan Tong Minh
7 *
8 * Implements regular file uploads
9 */
10 class UploadFromFile extends UploadBase {
11 protected $mWebUpload = null;
12
13 function initializeFromRequest( &$request ) {
14 $this->mWebUpload = $request->getUpload( 'wpUploadFile' );
15
16 $desiredDestName = $request->getText( 'wpDestFile' );
17 if( !$desiredDestName )
18 $desiredDestName = $this->mWebUpload->getName();
19 return $this->initializePathInfo(
20 $desiredDestName,
21 $this->mWebUpload->getTempName(),
22 $this->mWebUpload->getSize()
23 );
24 }
25 /**
26 * Entry point for upload from file.
27 */
28 function initialize( $name, $tempPath, $fileSize ) {
29 return $this->initializePathInfo( $name, $tempPath, $fileSize );
30 }
31 static function isValidRequest( $request ) {
32 # Allow all requests, even if no file is present, so that an error
33 # because a post_max_size or upload_max_filesize overflow
34 return true;
35 }
36
37 public function verifyUpload() {
38 # Check for a post_max_size or upload_max_size overflow, so that a
39 # proper error can be shown to the user
40 if ( is_null( $this->mTempPath ) || $this->isEmptyFile() ) {
41 # Using the Content-length header is not an absolutely fail-safe
42 # method, but the only available option. Otherwise broken uploads
43 # will be handled by the parent method and return empty-file
44 $contentLength = intval( $_SERVER['CONTENT_LENGTH'] );
45 $maxPostSize = wfShorthandToInteger( ini_get( 'post_max_size' ) );
46 if ( $this->mWebUpload->getError() == UPLOAD_ERR_INI_SIZE
47 || $contentLength > $maxPostSize ) {
48
49 global $wgMaxUploadSize;
50 return array(
51 'status' => self::FILE_TOO_LARGE,
52 'max' => min(
53 $wgMaxUploadSize,
54 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
55 $maxPostSize
56 ),
57 );
58 }
59 }
60
61 return parent::verifyUpload();
62 }
63 }