3 * Implements regular file uploads
7 * @author Bryan Tong Minh
10 class UploadFromFile
extends UploadBase
{
13 * @var WebRequestUpload
15 protected $mUpload = null;
18 * @param $request WebRequest
20 function initializeFromRequest( &$request ) {
21 $upload = $request->getUpload( 'wpUploadFile' );
22 $desiredDestName = $request->getText( 'wpDestFile' );
23 if( !$desiredDestName )
24 $desiredDestName = $upload->getName();
26 return $this->initialize( $desiredDestName, $upload );
30 * Initialize from a filename and a WebRequestUpload
32 function initialize( $name, $webRequestUpload ) {
33 $this->mUpload
= $webRequestUpload;
34 return $this->initializePathInfo( $name,
35 $this->mUpload
->getTempName(), $this->mUpload
->getSize() );
37 static function isValidRequest( $request ) {
38 # Allow all requests, even if no file is present, so that an error
39 # because a post_max_size or upload_max_filesize overflow
43 public function getSourceType() { return 'file'; }
45 public function verifyUpload() {
46 # Check for a post_max_size or upload_max_size overflow, so that a
47 # proper error can be shown to the user
48 if ( is_null( $this->mTempPath
) ||
$this->isEmptyFile() ) {
49 if ( $this->mUpload
->isIniSizeOverflow() ) {
51 'status' => UploadBase
::FILE_TOO_LARGE
,
53 self
::getMaxUploadSize( $this->getSourceType() ),
54 wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
55 wfShorthandToInteger( ini_get( 'post_max_size' ) )
61 return parent
::verifyUpload();
65 * Get the path to the file underlying the upload
66 * @return String path to file
68 public function getFileTempname() {
69 return $this->mUpload
->getTempname();