summaryrefslogtreecommitdiff
path: root/includes/upload/UploadFromFile.php
blob: e67ec191b0cfde84a2b1a2a8fed8074157b09126 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
 * Implements regular file uploads
 *
 * @file
 * @ingroup upload
 * @author Bryan Tong Minh
 */

class UploadFromFile extends UploadBase {
	protected $mUpload = null;

	function initializeFromRequest( &$request ) {
		$upload = $request->getUpload( 'wpUploadFile' );		
		$desiredDestName = $request->getText( 'wpDestFile' );
		if( !$desiredDestName )
			$desiredDestName = $upload->getName();
			
		return $this->initialize( $desiredDestName, $upload );
	}
	
	/**
	 * Initialize from a filename and a WebRequestUpload
	 */
	function initialize( $name, $webRequestUpload ) {
		$this->mUpload = $webRequestUpload;
		return $this->initializePathInfo( $name, 
			$this->mUpload->getTempName(), $this->mUpload->getSize() );
	}
	static function isValidRequest( $request ) {
		# Allow all requests, even if no file is present, so that an error
		# because a post_max_size or upload_max_filesize overflow
		return true;
	}
	
	public function verifyUpload() {
		# 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() ) {
			if ( $this->mUpload->isIniSizeOverflow() ) {
				global $wgMaxUploadSize;
				return array( 
					'status' => UploadBase::FILE_TOO_LARGE,
					'max' => min( 
						$wgMaxUploadSize, 
						wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ), 
						wfShorthandToInteger( ini_get( 'post_max_size' ) )
					),
				);
			}
		}
		
		return parent::verifyUpload();
	}

	/** 
	 * Get the path to the file underlying the upload
	 * @return String path to file
	 */
	public function getFileTempname() {
		return $this->mUpload->getTempname();
	}

	
}