Author: Jan Schneider (jan@horde.org)
Inheritance: extends Horde_Translation
示例#1
0
 /**
  * Determines if the file was uploaded or not.  If not, will return the
  * appropriate error message.
  *
  * @param string $field  The name of the field containing the uploaded
  *                       file.
  * @param string $name   The file description string to use in the error
  *                       message.  Default: 'file'.
  *
  * @throws Horde_Browser_Exception
  */
 public function wasFileUploaded($field, $name = null)
 {
     if (is_null($name)) {
         $name = 'file';
     }
     if (!($uploadSize = self::allowFileUploads())) {
         throw new Horde_Browser_Exception(Horde_Browser_Translation::t("File uploads not supported."));
     }
     /* Get any index on the field name. */
     $index = Horde_Array::getArrayParts($field, $base, $keys);
     if ($index) {
         /* Index present, fetch the error var to check. */
         $keys_path = array_merge(array($base, 'error'), $keys);
         $error = Horde_Array::getElement($_FILES, $keys_path);
         /* Index present, fetch the tmp_name var to check. */
         $keys_path = array_merge(array($base, 'tmp_name'), $keys);
         $tmp_name = Horde_Array::getElement($_FILES, $keys_path);
     } else {
         /* No index, simple set up of vars to check. */
         if (!isset($_FILES[$field])) {
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("No file uploaded"), UPLOAD_ERR_NO_FILE);
         }
         $error = $_FILES[$field]['error'];
         $tmp_name = $_FILES[$field]['tmp_name'];
     }
     if (empty($_FILES) || $error == UPLOAD_ERR_NO_FILE) {
         throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: No %s was uploaded."), $name), UPLOAD_ERR_NO_FILE);
     } elseif ($error == UPLOAD_ERR_OK && is_uploaded_file($tmp_name)) {
         if (!filesize($tmp_name)) {
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("The uploaded file appears to be empty. It may not exist on your computer."), UPLOAD_ERR_NO_FILE);
         }
         // SUCCESS
     } elseif ($error == UPLOAD_ERR_INI_SIZE || $error == UPLOAD_ERR_FORM_SIZE) {
         throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes)."), $name, $uploadSize), $error);
     } elseif ($error == UPLOAD_ERR_PARTIAL) {
         throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was only partially uploaded."), $name), $error);
     }
 }
示例#2
0
 /**
  * Determines if the file was uploaded or not.  If not, will return the
  * appropriate error message.
  *
  * @param string $field  The name of the field containing the uploaded
  *                       file.
  * @param string $name   The file description string to use in the error
  *                       message.  Default: 'file'.
  *
  * @throws Horde_Browser_Exception
  */
 public function wasFileUploaded($field, $name = null)
 {
     if (is_null($name)) {
         $name = 'file';
     }
     if (!($uploadSize = self::allowFileUploads())) {
         throw new Horde_Browser_Exception(Horde_Browser_Translation::t("File uploads not supported."));
     }
     /* Get any index on the field name. */
     $index = Horde_Array::getArrayParts($field, $base, $keys);
     if ($index) {
         /* Index present, fetch the error var to check. */
         $keys_path = array_merge(array($base, 'error'), $keys);
         $error = Horde_Array::getElement($_FILES, $keys_path);
         /* Index present, fetch the tmp_name var to check. */
         $keys_path = array_merge(array($base, 'tmp_name'), $keys);
         $tmp_name = Horde_Array::getElement($_FILES, $keys_path);
     } else {
         /* No index, simple set up of vars to check. */
         if (!isset($_FILES[$field])) {
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("No file uploaded"), UPLOAD_ERR_NO_FILE);
         }
         $error = $_FILES[$field]['error'];
         if (is_array($error)) {
             $error = reset($error);
         }
         $tmp_name = $_FILES[$field]['tmp_name'];
         if (is_array($tmp_name)) {
             $tmp_name = reset($tmp_name);
         }
     }
     if (empty($_FILES)) {
         $error = UPLOAD_ERR_NO_FILE;
     }
     switch ($error) {
         case UPLOAD_ERR_NO_FILE:
             throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: No %s was uploaded."), $name), UPLOAD_ERR_NO_FILE);
         case UPLOAD_ERR_OK:
             if (is_uploaded_file($tmp_name) && !filesize($tmp_name)) {
                 throw new Horde_Browser_Exception(Horde_Browser_Translation::t("The uploaded file appears to be empty. It may not exist on your computer."), UPLOAD_ERR_NO_FILE);
             }
             // SUCCESS
             break;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was larger than the maximum allowed size (%d bytes)."), $name, $uploadSize), $error);
         case UPLOAD_ERR_PARTIAL:
             throw new Horde_Browser_Exception(sprintf(Horde_Browser_Translation::t("There was a problem with the file upload: The %s was only partially uploaded."), $name), $error);
         case UPLOAD_ERR_NO_TMP_DIR:
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("There was a problem with the file upload: The temporary folder used to store the upload data is missing."), $error);
         case UPLOAD_ERR_CANT_WRITE:
             // No reason to try to explain to user what a "PHP extension" is.
         // No reason to try to explain to user what a "PHP extension" is.
         case UPLOAD_ERR_EXTENSION:
             throw new Horde_Browser_Exception(Horde_Browser_Translation::t("There was a problem with the file upload: Can't write the uploaded data to the server."), $error);
     }
 }
示例#3
0
 /**
  * Returns the plural translation of a message.
  *
  * @param string $singular  The singular version to translate.
  * @param string $plural    The plural version to translate.
  * @param integer $number   The number that determines singular vs. plural.
  *
  * @return string  The string translation, or the original string if no
  *                 translation exists.
  */
 public static function ngettext($singular, $plural, $number)
 {
     self::$_domain = 'Horde_Browser';
     self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Browser/locale';
     return parent::ngettext($singular, $plural, $number);
 }