Esempio n. 1
0
 /**
  * @return array
  */
 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();
 }
Esempio n. 2
0
 /**
  * Return the original filename of the uploaded file, as reported by
  * the submitting user agent. HTML-style character entities are
  * interpreted and normalized to Unicode normalization form C, in part
  * to deal with weird input from Safari with non-ASCII filenames.
  *
  * Other than this the name is not verified for being a safe filename.
  *
  * @param $key String:
  * @return string or NULL if no such file.
  */
 public function getFileName($key)
 {
     $file = new WebRequestUpload($this, $key);
     return $file->getName();
 }
 function initLogo()
 {
     $this->fileExtensions = array('gif', 'jpg', 'jpeg', 'png');
     $request = $this->getRequest();
     if (!$request->wasPosted()) {
         # GET requests just give the main form; no data except wpDestfile.
         return;
     }
     $this->gift_id = $request->getInt('gift_id');
     $this->mIgnoreWarning = $request->getCheck('wpIgnoreWarning');
     $this->mReUpload = $request->getCheck('wpReUpload');
     $this->mUpload = $request->getCheck('wpUpload');
     $this->mUploadDescription = $request->getText('wpUploadDescription');
     $this->mUploadCopyStatus = $request->getText('wpUploadCopyStatus');
     $this->mUploadSource = $request->getText('wpUploadSource');
     $this->mWatchthis = $request->getBool('wpWatchthis');
     wfDebug(__METHOD__ . ": watchthis is: '{$this->mWatchthis}'\n");
     $this->mAction = $request->getVal('action');
     $this->mSessionKey = $request->getInt('wpSessionKey');
     if (!empty($this->mSessionKey) && isset($_SESSION['wsUploadData'][$this->mSessionKey])) {
         /**
          * Confirming a temporarily stashed upload.
          * We don't want path names to be forged, so we keep
          * them in the session on the server and just give
          * an opaque key to the user agent.
          */
         $data = $_SESSION['wsUploadData'][$this->mSessionKey];
         $this->mUploadTempName = $data['mUploadTempName'];
         $this->mUploadSize = $data['mUploadSize'];
         $this->mOname = $data['mOname'];
         $this->mStashed = true;
     } else {
         /**
          * Check for a newly uploaded file.
          */
         $this->mUploadTempName = $request->getFileTempName('wpUploadFile');
         $file = new WebRequestUpload($request, 'wpUploadFile');
         $this->mUploadSize = $file->getSize();
         $this->mOname = $request->getFileName('wpUploadFile');
         $this->mSessionKey = false;
         $this->mStashed = false;
     }
 }
Esempio n. 4
0
 /**
  * uploadFile -- save file when is in proper format, do resize and
  * other stuffs
  *
  * @param Request $request -- WebRequest instance
  * @param String $input    -- name of file input in form
  * @param $errorMsg -- optional string containing details on what went wrong if there is an UPLOAD_ERR_EXTENSION.
  *
  * @return Integer -- error code of operation
  */
 public function uploadFile($request, $input = AVATAR_UPLOAD_FIELD, &$errorMsg = '')
 {
     global $wgTmpDirectory;
     wfProfileIn(__METHOD__);
     $this->__setLogType();
     if (!isset($wgTmpDirectory) || !is_dir($wgTmpDirectory)) {
         $wgTmpDirectory = '/tmp';
     }
     //		Wikia::log( __METHOD__, "tmp", "Temp directory set to {$wgTmpDirectory}" );
     $errorNo = $request->getUploadError($input);
     if ($errorNo != UPLOAD_ERR_OK) {
         //			Wikia::log( __METHOD__, "error", "Upload error {$errorNo}" );
         wfProfileOut(__METHOD__);
         return $errorNo;
     }
     $file = new WebRequestUpload($request, $input);
     $iFileSize = $file->getSize();
     if (empty($iFileSize)) {
         /**
          * file size = 0
          */
         //			Wikia::log( __METHOD__, 'empty', "Empty file {$input} reported size {$iFileSize}" );
         wfProfileOut(__METHOD__);
         return UPLOAD_ERR_NO_FILE;
     }
     $sTmpFile = $wgTmpDirectory . '/' . substr(sha1(uniqid($this->mUser->getID())), 0, 16);
     //		Wikia::log( __METHOD__, 'tmp', "Temp file set to {$sTmpFile}" );
     $sTmp = $request->getFileTempname($input);
     //		Wikia::log( __METHOD__, 'path', "Path to uploaded file is {$sTmp}" );
     if (move_uploaded_file($sTmp, $sTmpFile)) {
         $errorNo = $this->postProcessImageInternal($sTmpFile, $errorNo, $errorMsg);
     } else {
         //			Wikia::log( __METHOD__, 'move', sprintf('Cannot move uploaded file from %s to %s', $sTmp, $sTmpFile ));
         $errorNo = UPLOAD_ERR_CANT_WRITE;
     }
     wfProfileOut(__METHOD__);
     return $errorNo;
 }
Esempio n. 5
0
 /**
  * uploadFile -- save file when is in proper format, do resize and
  * other stuffs
  *
  * @param WebRequest $request -- WebRequest instance
  * @param String $input -- name of file input in form
  * @param $errorMsg -- optional string containing details on what went wrong if there is an UPLOAD_ERR_EXTENSION.
  *
  * @return Integer -- error code of operation
  */
 public function uploadFile($request, $input = AVATAR_UPLOAD_FIELD, &$errorMsg = '')
 {
     // macbre: avatars operations are disabled during maintenance
     global $wgAvatarsMaintenance;
     if (!empty($wgAvatarsMaintenance)) {
         return UPLOAD_ERR_NO_TMP_DIR;
     }
     wfProfileIn(__METHOD__);
     $this->__setLogType();
     $errorNo = $request->getUploadError($input);
     if ($errorNo != UPLOAD_ERR_OK) {
         wfProfileOut(__METHOD__);
         return $errorNo;
     }
     $file = new WebRequestUpload($request, $input);
     $iFileSize = $file->getSize();
     if (empty($iFileSize)) {
         /**
          * file size = 0
          */
         wfProfileOut(__METHOD__);
         return UPLOAD_ERR_NO_FILE;
     }
     $sTmpFile = $this->getTempFile();
     $sTmp = $request->getFileTempname($input);
     if (move_uploaded_file($sTmp, $sTmpFile)) {
         $errorNo = $this->postProcessImageInternal($sTmpFile, $errorNo, $errorMsg);
     } else {
         $errorNo = UPLOAD_ERR_CANT_WRITE;
     }
     wfProfileOut(__METHOD__);
     return $errorNo;
 }
 /**
  * Initialize the uploaded file from PHP data
  * @param $request WebRequest
  */
 protected function initializeUpload($request)
 {
     $file = new WebRequestUpload($request, 'wpUploadFile');
     $this->mTempPath = $file->getTempName();
     $this->mFileSize = $file->getSize();
     $this->mSrcName = $file->getName();
 }
Esempio n. 7
0
 /** 
  * Get the path to the file underlying the upload
  * @return String path to file
  */
 public function getFileTempname()
 {
     return $this->mUpload->getTempname();
 }