wiki.techinc.nl/includes/upload/UploadFromFile.php
Bryan Tong Minh db544af120 $wgMaxUploadSize may now be set to an array to specify the upload size limit per upload type.
Backwards compatible, if not set to an array, applies to all uploads. If set to an array, per upload type maximums can be set, using the file and url keys. If the * key is set this value will be used as maximum for non-specified types.
2011-01-06 19:42:55 +00:00

66 lines
1.7 KiB
PHP

<?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 getSourceType() { return 'file'; }
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() ) {
return array(
'status' => UploadBase::FILE_TOO_LARGE,
'max' => min(
self::getMaxUploadSize( $this->getSourceType() ),
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();
}
}