6 * @author Bryan Tong Minh
8 * Implements regular file uploads
10 class UploadFromFile
extends UploadBase
{
11 protected $mWebUpload = null;
13 function initializeFromRequest( &$request ) {
14 $this->mWebUpload
= $request->getUpload( 'wpUploadFile' );
16 $desiredDestName = $request->getText( 'wpDestFile' );
17 if( !$desiredDestName )
18 $desiredDestName = $this->mWebUpload
->getName();
19 return $this->initializePathInfo(
21 $this->mWebUpload
->getTempName(),
22 $this->mWebUpload
->getSize()
26 * Entry point for upload from file.
28 function initialize( $name, $tempPath, $fileSize ) {
29 return $this->initializePathInfo( $name, $tempPath, $fileSize );
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
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 ) {
49 global $wgMaxUploadSize;
51 'status' => self
::FILE_TOO_LARGE
,
54 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
61 return parent
::verifyUpload();