3 * Implements regular file uploads
6 * @author Bryan Tong Minh
8 class UploadFromFile
extends UploadBase
{
11 * @var WebRequestUpload
13 protected $mUpload = null;
16 * @param $request WebRequest
19 function initializeFromRequest( &$request ) {
20 $upload = $request->getUpload( 'wpUploadFile' );
21 $desiredDestName = $request->getText( 'wpDestFile' );
22 if( !$desiredDestName )
23 $desiredDestName = $upload->getName();
25 return $this->initialize( $desiredDestName, $upload );
29 * Initialize from a filename and a WebRequestUpload
31 * @param $webRequestUpload
34 function initialize( $name, $webRequestUpload ) {
35 $this->mUpload
= $webRequestUpload;
36 return $this->initializePathInfo( $name,
37 $this->mUpload
->getTempName(), $this->mUpload
->getSize() );
44 static function isValidRequest( $request ) {
45 # Allow all requests, even if no file is present, so that an error
46 # because a post_max_size or upload_max_filesize overflow
53 public function getSourceType() {
60 public function verifyUpload() {
61 # Check for a post_max_size or upload_max_size overflow, so that a
62 # proper error can be shown to the user
63 if ( is_null( $this->mTempPath
) ||
$this->isEmptyFile() ) {
64 if ( $this->mUpload
->isIniSizeOverflow() ) {
66 'status' => UploadBase
::FILE_TOO_LARGE
,
68 self
::getMaxUploadSize( $this->getSourceType() ),
69 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
70 wfShorthandToInteger( ini_get( 'post_max_size' ) )
76 return parent
::verifyUpload();