Skip to content

Commit

Permalink
Merge pull request #246 from joomlashack/DOWN-434
Browse files Browse the repository at this point in the history
Improve messaging for failed file uploads
  • Loading branch information
billtomczak authored Sep 12, 2022
2 parents ea4afb0 + 8fedfc3 commit ddcc9cb
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/admin/language/de-DE/de-DE.com_osdownloads.ini
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ COM_OSDOWNLOADS_SUPPORT_LINK = "Support Link"
COM_OSDOWNLOADS_THANK_YOU_PAGE = "Thank you page"

COM_OSDOWNLOADS_UPLOAD_ERR_CANT_WRITE = "Unable to write uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_EMPTY_FIELD = "Unable to find file name in form"
COM_OSDOWNLOADS_UPLOAD_ERR_EXTENSION = "A php extension stopped the file upload"
COM_OSDOWNLOADS_UPLOAD_ERR_FILENAME = "Unable to process file: %s"
COM_OSDOWNLOADS_UPLOAD_ERR_FILESYSTEM = "Unable to create the upload folder used to store files"
COM_OSDOWNLOADS_UPLOAD_ERR_FORM_SIZE = "The uploaded file exceeds the maximum file size set in the form"
COM_OSDOWNLOADS_UPLOAD_ERR_INI_SIZE = "The uploaded file exceeds php's maximum file size for uploads"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_FILE = "Unable to find uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_TMP_DIR = "There is no temporary directory set for php"
COM_OSDOWNLOADS_UPLOAD_ERR_PARTIAL = "The uploaded file was only partially uploaded"
COM_OSDOWNLOADS_UPLOAD_ERR_REQUIRED = "You must enter a file to upload"
COM_OSDOWNLOADS_UPLOAD_ERR_UNKNOWN = "An unknown error occurred while uploading the file (%s)"

COM_OSDOWNLOADS_UPLOAD_FILE = "Upload File"
COM_OSDOWNLOADS_UPLOAD_FILE_DESC = "If a current file has already been uploaded, you can overwrite it by uploading a new file."
4 changes: 4 additions & 0 deletions src/admin/language/en-GB/en-GB.com_osdownloads.ini
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ COM_OSDOWNLOADS_SUPPORT_LINK = "Support Link"
COM_OSDOWNLOADS_THANK_YOU_PAGE = "Thank you page"

COM_OSDOWNLOADS_UPLOAD_ERR_CANT_WRITE = "Unable to write uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_EMPTY_FIELD = "Unable to find file name in form"
COM_OSDOWNLOADS_UPLOAD_ERR_EXTENSION = "A php extension stopped the file upload"
COM_OSDOWNLOADS_UPLOAD_ERR_FILENAME = "Unable to process file: %s"
COM_OSDOWNLOADS_UPLOAD_ERR_FILESYSTEM = "Unable to create the upload folder used to store files"
COM_OSDOWNLOADS_UPLOAD_ERR_FORM_SIZE = "The uploaded file exceeds the maximum file size set in the form"
COM_OSDOWNLOADS_UPLOAD_ERR_INI_SIZE = "The uploaded file exceeds php's maximum file size for uploads"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_FILE = "Unable to find uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_TMP_DIR = "There is no temporary directory set for php"
COM_OSDOWNLOADS_UPLOAD_ERR_PARTIAL = "The uploaded file was only partially uploaded"
COM_OSDOWNLOADS_UPLOAD_ERR_REQUIRED = "You must enter a file to upload"
COM_OSDOWNLOADS_UPLOAD_ERR_UNKNOWN = "An unknown error occurred while uploading the file (%s)"

COM_OSDOWNLOADS_UPLOAD_FILE = "Upload File"
COM_OSDOWNLOADS_UPLOAD_FILE_DESC = "If a current file has already been uploaded, you can overwrite it by uploading a new file."
4 changes: 4 additions & 0 deletions src/admin/language/es-ES/es-ES.com_osdownloads.ini
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,17 @@ COM_OSDOWNLOADS_SUPPORT_LINK = "Enlace de soporte"
COM_OSDOWNLOADS_THANK_YOU_PAGE = "Página de ´Gracias´,"

COM_OSDOWNLOADS_UPLOAD_ERR_CANT_WRITE = "No se puede sobe escribir el archivo cargado"
COM_OSDOWNLOADS_UPLOAD_ERR_EMPTY_FIELD = "Unable to find file name in form"
COM_OSDOWNLOADS_UPLOAD_ERR_EXTENSION = "Una extensión php detuvo ls carga del archivo."
COM_OSDOWNLOADS_UPLOAD_ERR_FILENAME = "No se puede procesar el archivo: %s"
COM_OSDOWNLOADS_UPLOAD_ERR_FILESYSTEM = "No se puede crear la Carpeta de carga para uso de los archivos cargados"
COM_OSDOWNLOADS_UPLOAD_ERR_FORM_SIZE = "El archivo cargado excede el límite máximo del tamaño establecido en el formulario"
COM_OSDOWNLOADS_UPLOAD_ERR_INI_SIZE = "El archivo cargado excede el límite máximo del tamaño establecido en php"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_FILE = "Unable to find uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_TMP_DIR = "No existe una directorio temporario establecido para php"
COM_OSDOWNLOADS_UPLOAD_ERR_PARTIAL = "El archivo ha sido cargado parcialmente"
COM_OSDOWNLOADS_UPLOAD_ERR_REQUIRED = "You must enter a file to upload"
COM_OSDOWNLOADS_UPLOAD_ERR_UNKNOWN = "Un error desconocido ocurrió cuando se estaba cargando el archivo (%s)"

COM_OSDOWNLOADS_UPLOAD_FILE = "Cargar archivo"
COM_OSDOWNLOADS_UPLOAD_FILE_DESC = "Si ya se ha cargado un archivo, puede sobre escribirlo cargando un nuevo archivo."
4 changes: 4 additions & 0 deletions src/admin/language/fa-IR/fa-IR.com_osdownloads.ini
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ COM_OSDOWNLOADS_SUPPORT_LINK = "لینک پشتیبانی"
COM_OSDOWNLOADS_THANK_YOU_PAGE = "صفحه تشکر"

COM_OSDOWNLOADS_UPLOAD_ERR_CANT_WRITE = "Unable to write uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_EMPTY_FIELD = "Unable to find file name in form"
COM_OSDOWNLOADS_UPLOAD_ERR_EXTENSION = "A php extension stopped the file upload"
COM_OSDOWNLOADS_UPLOAD_ERR_FILENAME = "Unable to process file: %s"
COM_OSDOWNLOADS_UPLOAD_ERR_FILESYSTEM = "Unable to create the upload folder used to store files"
COM_OSDOWNLOADS_UPLOAD_ERR_FORM_SIZE = "The uploaded file exceeds the maximum file size set in the form"
COM_OSDOWNLOADS_UPLOAD_ERR_INI_SIZE = "The uploaded file exceeds php's maximum file size for uploads"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_FILE = "Unable to find uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_TMP_DIR = "There is no temporary directory set for php"
COM_OSDOWNLOADS_UPLOAD_ERR_PARTIAL = "The uploaded file was only partially uploaded"
COM_OSDOWNLOADS_UPLOAD_ERR_REQUIRED = "You must enter a file to upload"
COM_OSDOWNLOADS_UPLOAD_ERR_UNKNOWN = "An unknown error occurred while uploading the file (%s)"

COM_OSDOWNLOADS_UPLOAD_FILE = "آپلود فایل"
COM_OSDOWNLOADS_UPLOAD_FILE_DESC = "اگر یک فایل فعلی در حال بارگیری است، می توانید با آپلود یک فایل جدید آن را بازنویسی کنید."
4 changes: 4 additions & 0 deletions src/admin/language/fr-FR/fr-FR.com_osdownloads.ini
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ COM_OSDOWNLOADS_SUPPORT_LINK = "Lien de support"
COM_OSDOWNLOADS_THANK_YOU_PAGE = "Page de remerciement"
COM_OSDOWNLOADS_UPLOAD_ERR_CANT_WRITE = "Unable to write uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_EMPTY_FIELD = "Unable to find file name in form"
COM_OSDOWNLOADS_UPLOAD_ERR_EXTENSION = "A php extension stopped the file upload"
COM_OSDOWNLOADS_UPLOAD_ERR_FILENAME = "Unable to process file: %s"
COM_OSDOWNLOADS_UPLOAD_ERR_FILESYSTEM = "Unable to create the upload folder used to store files"
COM_OSDOWNLOADS_UPLOAD_ERR_FORM_SIZE = "The uploaded file exceeds the maximum file size set in the form"
COM_OSDOWNLOADS_UPLOAD_ERR_INI_SIZE = "The uploaded file exceeds php's maximum file size for uploads"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_FILE = "Unable to find uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_TMP_DIR = "There is no temporary directory set for php"
COM_OSDOWNLOADS_UPLOAD_ERR_PARTIAL = "The uploaded file was only partially uploaded"
COM_OSDOWNLOADS_UPLOAD_ERR_REQUIRED = "You must enter a file to upload"
COM_OSDOWNLOADS_UPLOAD_ERR_UNKNOWN = "An unknown error occurred while uploading the file (%s)"
COM_OSDOWNLOADS_UPLOAD_FILE = "Téléverser le fichier"
COM_OSDOWNLOADS_UPLOAD_FILE_DESC = "Si un fichier en cours a déjà été chargé, vous pouvez l'écraser en téléchargeant un nouveau fichier."
4 changes: 4 additions & 0 deletions src/admin/language/it-IT/it-IT.com_osdownloads.ini
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ COM_OSDOWNLOADS_SUPPORT_LINK = "Support Link"
COM_OSDOWNLOADS_THANK_YOU_PAGE = "Thank you page"

COM_OSDOWNLOADS_UPLOAD_ERR_CANT_WRITE = "Unable to write uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_EMPTY_FIELD = "Unable to find file name in form"
COM_OSDOWNLOADS_UPLOAD_ERR_EXTENSION = "A php extension stopped the file upload"
COM_OSDOWNLOADS_UPLOAD_ERR_FILENAME = "Unable to process file: %s"
COM_OSDOWNLOADS_UPLOAD_ERR_FILESYSTEM = "Unable to create the upload folder used to store files"
COM_OSDOWNLOADS_UPLOAD_ERR_FORM_SIZE = "The uploaded file exceeds the maximum file size set in the form"
COM_OSDOWNLOADS_UPLOAD_ERR_INI_SIZE = "The uploaded file exceeds php's maximum file size for uploads"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_FILE = "Unable to find uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_TMP_DIR = "There is no temporary directory set for php"
COM_OSDOWNLOADS_UPLOAD_ERR_PARTIAL = "The uploaded file was only partially uploaded"
COM_OSDOWNLOADS_UPLOAD_ERR_REQUIRED = "You must enter a file to upload"
COM_OSDOWNLOADS_UPLOAD_ERR_UNKNOWN = "An unknown error occurred while uploading the file (%s)"

COM_OSDOWNLOADS_UPLOAD_FILE = "Upload File"
COM_OSDOWNLOADS_UPLOAD_FILE_DESC = "If a current file has already been uploaded, you can overwrite it by uploading a new file."
4 changes: 4 additions & 0 deletions src/admin/language/nl-NL/nl-NL.com_osdownloads.ini
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,17 @@ COM_OSDOWNLOADS_SUPPORT_LINK = "Support Link"
COM_OSDOWNLOADS_THANK_YOU_PAGE = "Bedankt pagina"

COM_OSDOWNLOADS_UPLOAD_ERR_CANT_WRITE = "Kan geüploade bestand niet schrijven"
COM_OSDOWNLOADS_UPLOAD_ERR_EMPTY_FIELD = "Unable to find file name in form"
COM_OSDOWNLOADS_UPLOAD_ERR_EXTENSION = "Een php-extensie stopte het uploaden van het bestand"
COM_OSDOWNLOADS_UPLOAD_ERR_FILENAME = "Kan bestand niet verwerken: %s"
COM_OSDOWNLOADS_UPLOAD_ERR_FILESYSTEM = "Kan de uploadmap niet aanmaken om bestanden op te slaan"
COM_OSDOWNLOADS_UPLOAD_ERR_FORM_SIZE = "Het geüploade bestand overschrijdt de maximale bestandsgrootte die in het formulier is ingesteld"
COM_OSDOWNLOADS_UPLOAD_ERR_INI_SIZE = "Het geüploade bestand overschrijdt php's maximale bestandsgrootte voor uploads"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_FILE = "Unable to find uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_TMP_DIR = "Er is geen tijdelijke map ingesteld voor php"
COM_OSDOWNLOADS_UPLOAD_ERR_PARTIAL = "Het geüploade bestand is slechts gedeeltelijk geüpload"
COM_OSDOWNLOADS_UPLOAD_ERR_REQUIRED = "You must enter a file to upload"
COM_OSDOWNLOADS_UPLOAD_ERR_UNKNOWN = "Er is een onbekende fout opgetreden tijdens het uploaden van het bestand (%s)"

COM_OSDOWNLOADS_UPLOAD_FILE = "Upload Bestand"
COM_OSDOWNLOADS_UPLOAD_FILE_DESC = "Als een huidig bestand al is geüpload, kunt u het overschrijven door een nieuw bestand te uploaden."
4 changes: 4 additions & 0 deletions src/admin/language/pt-BR/pt-BR.com_osdownloads.ini
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,17 @@ COM_OSDOWNLOADS_SUPPORT_LINK = "Link para o suporte"
COM_OSDOWNLOADS_THANK_YOU_PAGE = "Página de agradecimento"

COM_OSDOWNLOADS_UPLOAD_ERR_CANT_WRITE = "Unable to write uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_EMPTY_FIELD = "Unable to find file name in form"
COM_OSDOWNLOADS_UPLOAD_ERR_EXTENSION = "A php extension stopped the file upload"
COM_OSDOWNLOADS_UPLOAD_ERR_FILENAME = "Unable to process file: %s"
COM_OSDOWNLOADS_UPLOAD_ERR_FILESYSTEM = "Unable to create the upload folder used to store files"
COM_OSDOWNLOADS_UPLOAD_ERR_FORM_SIZE = "The uploaded file exceeds the maximum file size set in the form"
COM_OSDOWNLOADS_UPLOAD_ERR_INI_SIZE = "The uploaded file exceeds php's maximum file size for uploads"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_FILE = "Unable to find uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_TMP_DIR = "There is no temporary directory set for php"
COM_OSDOWNLOADS_UPLOAD_ERR_PARTIAL = "The uploaded file was only partially uploaded"
COM_OSDOWNLOADS_UPLOAD_ERR_REQUIRED = "You must enter a file to upload"
COM_OSDOWNLOADS_UPLOAD_ERR_UNKNOWN = "An unknown error occurred while uploading the file (%s)"

COM_OSDOWNLOADS_UPLOAD_FILE = "Enviar arquivo"
COM_OSDOWNLOADS_UPLOAD_FILE_DESC = "Se um arquivo atual já tiver sido enviado, você pode substituí-lo fazendo o upload de um novo arquivo."
4 changes: 4 additions & 0 deletions src/admin/language/sl-SI/sl-SI.com_osdownloads.ini
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@ COM_OSDOWNLOADS_SUPPORT_LINK = "Povezava za podporo"
COM_OSDOWNLOADS_THANK_YOU_PAGE = "Zahvalna stran"

COM_OSDOWNLOADS_UPLOAD_ERR_CANT_WRITE = "Naložene datoteke ni mogoče zapisati"
COM_OSDOWNLOADS_UPLOAD_ERR_EMPTY_FIELD = "Unable to find file name in form"
COM_OSDOWNLOADS_UPLOAD_ERR_EXTENSION = "Razširitev php je ustavila nalaganje datoteke"
COM_OSDOWNLOADS_UPLOAD_ERR_FILENAME = "Datoteke ni mogoče obdelati: %s"
COM_OSDOWNLOADS_UPLOAD_ERR_FILESYSTEM = "Mape za nalaganje, ki se uporablja za shranjevanje datotek, ni mogoče ustvariti"
COM_OSDOWNLOADS_UPLOAD_ERR_FORM_SIZE = "Naložena datoteka presega največjo dovoljeno velikost datoteke, nastavljeno v obrazcu"
COM_OSDOWNLOADS_UPLOAD_ERR_INI_SIZE = "Naložena datoteka presega največjo dovoljeno velikost php za nalaganja"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_FILE = "Unable to find uploaded file"
COM_OSDOWNLOADS_UPLOAD_ERR_NO_TMP_DIR = "Za php ni nastavljen začasni imenik"
COM_OSDOWNLOADS_UPLOAD_ERR_PARTIAL = "Naložena datoteka je bila naložena le delno"
COM_OSDOWNLOADS_UPLOAD_ERR_REQUIRED = "You must enter a file to upload"
COM_OSDOWNLOADS_UPLOAD_ERR_UNKNOWN = "Med nalaganjem datoteke (%s) je prišlo do neznane napake"

COM_OSDOWNLOADS_UPLOAD_FILE = "Naloži datoteko"
COM_OSDOWNLOADS_UPLOAD_FILE_DESC = "Če je trenutna datoteka že naložena, jo lahko prepišete tako, da naložite novo datoteko."
22 changes: 17 additions & 5 deletions src/admin/models/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class OSDownloadsModelFile extends AdminModel

/**
* @inheritDoc
* @throws Exception
*/
public function getForm($data = [], $loadData = true)
{
Expand Down Expand Up @@ -181,6 +182,7 @@ public function save($data)
}

} catch (Throwable $e) {
$this->setError($e->getMessage());
return false;
}

Expand Down Expand Up @@ -240,16 +242,26 @@ protected function uploadFile(&$data)
{
$app = Factory::getApplication();
$files = $app->input->files->get('jform', [], 'raw');
$upload = new Registry($files['file_path_upload']);

$fileName = $upload->get('name');
if (empty($fileName)) {
if (empty($data['file_path'])) {
if (isset($files['file_path_upload']['name'])) {
$error = 'COM_OSDOWNLOADS_UPLOAD_ERR_REQUIRED';
} else {
$error = 'COM_OSDOWNLOADS_UPLOAD_ERR_EMPTY_FIELD';
}

throw new Exception(Text::_($error));
}

if (empty($files['file_path_upload'])) {
return;
}

$upload = new Registry($files['file_path_upload']);

$uploadError = $upload->get('error');
if ($uploadError == UPLOAD_ERR_NO_FILE) {
return;
throw New Exception(Text::_('COM_OSDOWNLOADS_UPLOAD_ERR_NO_FILE'));

} elseif ($uploadError != UPLOAD_ERR_OK) {
if (isset($this->uploadErrors[$uploadError])) {
Expand All @@ -262,7 +274,7 @@ protected function uploadFile(&$data)
throw new Exception($errorMessage);
}

if ($fileName = File::makeSafe($upload->get('name'))) {
if ($fileName = File::makeSafe($fileName)) {
if (!is_dir($this->uploadDir)) {
if (is_file($this->uploadDir)) {
throw new Exception(Text::_('COM_OSDOWNLOADS_UPLOAD_ERR_FILESYSTEM'));
Expand Down

0 comments on commit ddcc9cb

Please sign in to comment.