Example #1
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;
 }