Example #1
0
 public function processRequest()
 {
     // Ignore other requests except POST.
     if ($_SERVER['REQUEST_METHOD'] !== 'POST' || empty($_POST[PostFields::packageGuid])) {
         return;
     }
     if (UploadHandler::$_processed) {
         return;
     }
     UploadHandler::$_processed = true;
     if (array_key_exists('HTTP_X_PREPROCESS_REQUIRED', $_SERVER) && $_SERVER['HTTP_X_PREPROCESS_REQUIRED'] == 'true') {
         $files = $this->getRequestFiles($_POST);
     } else {
         $files =& $_FILES;
     }
     $uploadCache = new UploadCache($this->_cacheRoot);
     $uploadSession = new UploadSession($uploadCache, $_POST, $files, $_SERVER);
     if (!empty($this->_allFilesUploadedCallback)) {
         $uploadSession->setAllFilesUploadedCallback($this->_allFilesUploadedCallback);
     }
     if (!empty($this->_fileUploadedCallback)) {
         $uploadSession->setFileUploadedCallback($this->_fileUploadedCallback);
     }
     $uploadSession->processRequest();
     $this->removeExpiredSessions($uploadCache);
     // Flash requires non-empty response
     if (!headers_sent() && array_key_exists('HTTP_USER_AGENT', $_SERVER) && $_SERVER['HTTP_USER_AGENT'] === 'Shockwave Flash') {
         echo '0';
     }
 }
Example #2
0
	/**
	 * Processes server and $_FILE info relating to uploads to produce usable info. Assigns all gathered data to class variables which are accessible via public methods.
	 *
	 * @return void
	 * @throws UploadHandlerProcessPostSizeException If the posted data size exceeds the maximum post size defined by php configuration
	 * @throws UploadHandlerProcessNoInputException If no files were uploaded
	 */
	public static function processUploads()
	{
		if (self::$_processed) {
			return;
		}

		self::$_processed = true;

		self::$files = array();

		if (self::$contentLength >= self::$maxPostSize) {
			//	post length exceeds maximum post length ini directive - impossible for php to parse uploaded files because $_FILES is empty
			throw new UploadHandlerProcessPostSizeException(sprintf(self::$i18n['UPLOADHANDLER_ERR_PROCESS_POST_SIZE'], self::$contentLength, self::$maxPostSize));
		}

		if (empty($_FILES)) {
			//	no files uploaded
			throw new UploadHandlerProcessNoInputException(self::$i18n['UPLOADHANDLER_ERR_PROCESS_NO_INPUT']);
		}

		foreach ($_FILES as $fieldName => $field) {

			if (is_array($field['name'])) {
				//	input field that uses [] in it's name

				self::$files[$fieldName] = array();

				foreach ($field['name'] as $index => $ignoreThisValue) {
					$name = $field['name'][$index];
					$type = $field['type'][$index];
					$tmp_name = $field['tmp_name'][$index];
					$error = intval($field['error'][$index]);
					$size = intval($field['size'][$index]);

					$file = new UploadHandlerFile($fieldName, $name, $type, $tmp_name, $error, $size);

					self::$files[$fieldName][] = $file;
				}

			} else {
				//	single input field
				$name = $field['name'];
				$type = $field['type'];
				$tmp_name = $field['tmp_name'];
				$error = intval($field['error']);
				$size = intval($field['size']);

				$file = new UploadHandlerFile($fieldName, $name, $type, $tmp_name, $error, $size);

				self::$files[$fieldName] = array($file);
			}
		}
	}