Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 52 additions & 16 deletions core/functions/actions/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,27 @@ function rrmdir($dir)
}
}

if (!function_exists('fileManagerUploadSummary')) {
/**
* The head of an upload report: how many of the files the user picked were stored, and how many never
* reached PHP, which drops every file past max_file_uploads without a trace.
*/
function fileManagerUploadSummary(array $lang, int $selected, int $received, int $uploaded, int $maxFileUploads): string
{
$total = max($selected, $received);
$text = static fn (string $key, array $values): string => htmlspecialchars(vsprintf($lang[$key] ?? $key, $values), ENT_QUOTES, 'UTF-8');
$html = '<p class="upload-summary"><span class="' . ($uploaded < $total ? 'warning' : 'success') . '"><b>'
. $text('files_upload_summary', [$uploaded, $total]) . '</b></span></p>';
if ($selected > $received) {
$html .= '<p class="upload-dropped"><span class="warning">'
. $text('files_upload_not_received', [$selected - $received, $maxFileUploads]) . ' '
. $text('files_upload_zip_hint', []) . '</span></p>';
}

return $html;
}
}

if(!function_exists('fileupload')) {
/**
* @return string
Expand Down Expand Up @@ -1945,10 +1966,16 @@ function fileupload()
$dirGroupIds = fileManagerEffectiveGroupIds($dirRel);
}
$inheritInserts = [];
$received = 0;
$uploaded = 0;
foreach ($_FILES['userfile']['name'] as $i => $name) {
if (empty($_FILES['userfile']['tmp_name'][$i])) {
// only an empty file field; a file PHP refused (too large, partial) has no tmp_name either and is reported
if ((int) ($_FILES['userfile']['error'][$i] ?? UPLOAD_ERR_NO_FILE) === UPLOAD_ERR_NO_FILE) {
continue;
}
$received++;
$fileMsg = '';
$fileUploaded = false;
$userfile = [];

$userfile['tmp_name'] = $_FILES['userfile']['tmp_name'][$i];
Expand All @@ -1971,11 +1998,11 @@ function fileupload()
// this seems to be an upload action.
$rel_path = ltrim(substr($startpath, strlen($filemanager_path)), '/');
$path = EVO_SITE_URL . ($rel_path ? $rel_path . '/' : '') . $userfile['name'];
$msg .= htmlspecialchars($path, ENT_QUOTES, 'UTF-8');
$fileMsg .= htmlspecialchars($path, ENT_QUOTES, 'UTF-8');
if ($userfile['error'] == 0) {
$img = (strpos($userfile['type'],'image') !== false) ? '<br /><img src="'
. htmlspecialchars($path, ENT_QUOTES, 'UTF-8') . '" height="75" />' : '';
$msg .= "<p>" . $_lang['files_file_type'] . htmlspecialchars($userfile['type'], ENT_QUOTES,
$fileMsg .= "<p>" . $_lang['files_file_type'] . htmlspecialchars($userfile['type'], ENT_QUOTES,
'UTF-8') . ", " . niceSize(filesize($userfile['tmp_name'])) . $img . '</p>';
}

Expand All @@ -1984,7 +2011,7 @@ function fileupload()
if (is_uploaded_file($userfilename)) {
// file is uploaded file, process it!
if (!checkExtension($userfile['name'])) {
$msg .= '<p><span class="warning">' . $_lang['files_filetype_notok'] . '</span></p>';
$fileMsg .= '<p><span class="warning">' . $_lang['files_filetype_notok'] . '</span></p>';
} else {
$targetFile = $startpath . '/' . $userfile['name'];
// a replaced file is a modified file: its own restrictions apply, not just the folder's.
Expand All @@ -1993,14 +2020,16 @@ function fileupload()
$replacing = file_exists($targetFile);
if ($replacing && !fileManagerCanModifyExistingPath($existingRel)) {
fileManagerLogDenied('upload over existing file', $existingRel, 'file group');
$msg .= '<p><span class="warning">' . $_lang['files_access_denied'] . '</span></p>';
$fileMsg .= '<p><span class="warning">' . $_lang['files_access_denied'] . '</span></p>';
} elseif (@move_uploaded_file($userfile['tmp_name'], $targetFile)) {
// Ryan: Repair broken permissions issue with file manager
if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
@chmod($targetFile, $new_file_permissions);
}
// Ryan: End
$msg .= '<p><span class="success">' . $_lang['files_upload_ok'] . '</span></p><hr/>';
$fileMsg .= '<p><span class="success">' . $_lang['files_upload_ok'] . '</span></p><hr/>';
$uploaded++;
$fileUploaded = true;

// invoke OnFileManagerUpload event
$modx->invokeEvent('OnFileManagerUpload', [
Expand All @@ -2018,41 +2047,48 @@ function fileupload()
}
}
} else {
$msg .= '<p><span class="warning">' . $_lang['files_upload_copyfailed'] . '</span> '
$fileMsg .= '<p><span class="warning">' . $_lang['files_upload_copyfailed'] . '</span> '
. $_lang["files_upload_permissions_error"] . '</p>';
}
}
} else {
$msg .= '<br /><span class="warning"><b>' . $_lang['files_upload_error'] . ':</b>';
$fileMsg .= '<br /><span class="warning"><b>' . $_lang['files_upload_error'] . ':</b>';
switch ($userfile['error']) {
case 0: //no error; possible file attack!
$msg .= $_lang['files_upload_error0'];
$fileMsg .= $_lang['files_upload_error0'];
break;
case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
$msg .= $_lang['files_upload_error1'];
$fileMsg .= $_lang['files_upload_error1'];
break;
case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
$msg .= $_lang['files_upload_error2'];
$fileMsg .= $_lang['files_upload_error2'];
break;
case 3: //uploaded file was only partially uploaded
$msg .= $_lang['files_upload_error3'];
$fileMsg .= $_lang['files_upload_error3'];
break;
case 4: //no file was uploaded
$msg .= $_lang['files_upload_error4'];
$fileMsg .= $_lang['files_upload_error4'];
break;
default: //a default error, just in case! :)
$msg .= $_lang['files_upload_error5'];
$fileMsg .= $_lang['files_upload_error5'];
break;
}
$msg .= '</span><br />';
$fileMsg .= '</span><br />';
}
// one block per file, so a page can show the failed ones first
$msg .= '<div class="upload-file ' . ($fileUploaded ? 'upload-ok' : 'upload-failed') . '">' . $fileMsg . '</div>';
}

if (!empty($inheritInserts)) {
\EvolutionCMS\Models\FileGroup::query()->insertOrIgnore($inheritInserts);
}

return $msg . '<br/>';
// the number of files the browser sent in this request, to tell the ones PHP dropped
$selected = max(0, (int) ($_POST['upload_selected'] ?? 0));
$summary = fileManagerUploadSummary($_lang, $selected, $received, $uploaded, (int) ini_get('max_file_uploads'));

return '<div id="uploadReport" data-uploaded="' . $uploaded . '" data-total="' . max($selected, $received) . '">'
. $summary . $msg . '</div><br/>';
}
}

Expand Down
7 changes: 7 additions & 0 deletions core/lang/az/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@
$_lang["files_upload_error5"] = 'Yükləmə zamanı problem yarandı.';
$_lang["files_upload_inhibited_msg"] = '<b>Yükləmə funksiyası məhdudlaşdırılıb</b> - yükləmələrin dəstəkləndiyinə və qovluğun PHP üçün yazıla bilən olduğuna əmin olun.';
$_lang["files_upload_ok"] = 'Fayl uğurla yükləndi!';
$_lang["files_upload_summary"] = '%2$s fayldan %1$s fayl yükləndi.';
$_lang["files_upload_not_received"] = '%1$s fayl serverə çatmadı: server bir yükləmədə ən çox %2$s fayl qəbul edir.';
$_lang["files_upload_zip_hint"] = 'Onları yenidən yükləyin və ya bir ZIP faylına yığın, onu yükləyin və burada açın.';
$_lang["files_upload_progress"] = 'Fayllar yüklənir: %1$s-%2$s / %3$s...';
$_lang["files_upload_details"] = 'Yüklənmiş fayllar';
$_lang["files_upload_file_skipped"] = '"%1$s" faylının ölçüsü %2$s, lakin faylın ölçüsü ən çox %3$s ola bilər: fayl yüklənmədi.';
$_lang["files_upload_stopped"] = 'Yükləmə dayandı (%1$s). Bu %2$s fayl yüklənmədi: %3$s';
$_lang["files_upload_permissions_error"] = 'İcazə problemi ola bilər - yükləmək istədiyiniz qovluq veb-serveriniz tərəfindən yazıla bilən olmalıdır.';
$_lang["files_uploadfile"] = 'Fayl yüklə';
$_lang["files_uploadfile_msg"] = 'Yükləmək üçün fayl seçin:';
Expand Down
7 changes: 7 additions & 0 deletions core/lang/be/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@
$_lang["files_upload_error5"] = 'Узнікла памылка падчас загрузкі.';
$_lang["files_upload_inhibited_msg"] = '<b>Функцыя загрузкі забароненая</b> - пераканайцеся, што загрузкі дазволены і каталог даступны для запісу для PHP.';
$_lang["files_upload_ok"] = 'Файл паспяхова загружаны!';
$_lang["files_upload_summary"] = 'Загружана %1$s з %2$s файлаў.';
$_lang["files_upload_not_received"] = '%1$s файлаў не дайшлі да сервера: ён прымае не больш за %2$s файлаў за адну загрузку.';
$_lang["files_upload_zip_hint"] = 'Загрузіце іх яшчэ раз або спакуйце ў адзін ZIP-файл, загрузіце яго і распакуйце тут.';
$_lang["files_upload_progress"] = 'Загрузка файлаў %1$s-%2$s з %3$s...';
$_lang["files_upload_details"] = 'Загружаныя файлы';
$_lang["files_upload_file_skipped"] = 'Памер «%1$s» — %2$s, але файл можа быць не больш за %3$s: ён не загружаны.';
$_lang["files_upload_stopped"] = 'Загрузка спынілася (%1$s). Гэтыя файлы (%2$s) не загружаны: %3$s';
$_lang["files_upload_permissions_error"] = 'Магчымыя праблемы з дазволамі - каталог, у які вы хочаце загрузіць файл, павінен быць даступным для запісу вашым вэб-серверам.';
$_lang["files_uploadfile"] = 'Загрузіць файл';
$_lang["files_uploadfile_msg"] = 'Выберыце файл для загрузкі:';
Expand Down
7 changes: 7 additions & 0 deletions core/lang/bg/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@
$_lang["files_upload_error5"] = 'Възникна проблем при ъплоудването.';
$_lang["files_upload_inhibited_msg"] = '<b>Опцията за ъплоудване е забранена</b> - уверете се, че се поддържа ъплоудване и директорията е достъпна за запис за PHP.<br />';
$_lang["files_upload_ok"] = 'Файлът е ъплоуднат успешно!';
$_lang["files_upload_summary"] = 'Ъплоуднати са %1$s от %2$s файла.';
$_lang["files_upload_not_received"] = '%1$s файла не достигнаха сървъра: той приема най-много %2$s файла при едно ъплоудване.';
$_lang["files_upload_zip_hint"] = 'Ъплоуднете ги отново или ги пакетирайте в един ZIP файл, ъплоуднете го и го разархивирайте тук.';
$_lang["files_upload_progress"] = 'Ъплоудване на файлове %1$s-%2$s от %3$s...';
$_lang["files_upload_details"] = 'Ъплоуднати файлове';
$_lang["files_upload_file_skipped"] = '„%1$s“ е %2$s, но файлът може да бъде най-много %3$s: не е ъплоуднат.';
$_lang["files_upload_stopped"] = 'Ъплоудването спря (%1$s). Тези %2$s файла не са ъплоуднати: %3$s';
$_lang["files_upload_permissions_error"] = 'Possible permission problems - the directory you want to upload to needs to be writable by your webserver.';
$_lang["files_uploadfile"] = 'Ъплоудване на файл';
$_lang["files_uploadfile_msg"] = 'Избор на файл за ъплоудване:';
Expand Down
7 changes: 7 additions & 0 deletions core/lang/cs/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@
$_lang["files_upload_error5"] = 'Vyskytnul se problém při nahrávání souboru.';
$_lang["files_upload_inhibited_msg"] = '<b>Do tohoto adresáře se nedají nahrávat soubory</b> - presvěčte se, zda jsou do tohoto adresáře nastavená práva pro zápis.<br />';
$_lang["files_upload_ok"] = 'Soubor byl úspěšně nahrán!';
$_lang["files_upload_summary"] = 'Nahráno %1$s z %2$s souborů.';
$_lang["files_upload_not_received"] = 'Na server nedorazilo %1$s souborů: v jednom nahrávání přijme nejvýše %2$s souborů.';
$_lang["files_upload_zip_hint"] = 'Nahrajte je znovu, nebo je zabalte do jednoho souboru ZIP, nahrajte ho a rozbalte zde.';
$_lang["files_upload_progress"] = 'Nahrávají se soubory %1$s-%2$s z %3$s...';
$_lang["files_upload_details"] = 'Nahrané soubory';
$_lang["files_upload_file_skipped"] = 'Soubor „%1$s“ má %2$s, ale soubor smí mít nejvýše %3$s: nebyl nahrán.';
$_lang["files_upload_stopped"] = 'Nahrávání se zastavilo (%1$s). Tyto soubory (%2$s) nebyly nahrány: %3$s';
$_lang["files_upload_permissions_error"] = 'Možný problém s oprávněním - adresář, do kterého chcete nahrávat soubory musí mít povoleno zapisování servrem.';
$_lang["files_uploadfile"] = 'Nahrát soubor';
$_lang["files_uploadfile_msg"] = 'Vybrat soubor pro nahrání:';
Expand Down
7 changes: 7 additions & 0 deletions core/lang/da/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@
$_lang["files_upload_error5"] = 'Der opstod et problem under upload.';
$_lang["files_upload_inhibited_msg"] = '<b>Upload funktionen er deaktiveret</b> - kontroller at upload er understøttet, samt at mappen er skrivbar for PHP.';
$_lang["files_upload_ok"] = 'Upload blev gennemført!';
$_lang["files_upload_summary"] = 'Uploadede %1$s af %2$s filer.';
$_lang["files_upload_not_received"] = '%1$s filer nåede ikke frem til serveren: den modtager højst %2$s filer i én upload.';
$_lang["files_upload_zip_hint"] = 'Upload dem igen, eller pak dem i én ZIP-fil, upload den og pak den ud her.';
$_lang["files_upload_progress"] = 'Uploader filer %1$s-%2$s af %3$s...';
$_lang["files_upload_details"] = 'Uploadede filer';
$_lang["files_upload_file_skipped"] = '"%1$s" er %2$s, men en fil må højst være %3$s: den blev ikke uploadet.';
$_lang["files_upload_stopped"] = 'Uploaden stoppede (%1$s). Disse %2$s filer blev ikke uploadet: %3$s';
$_lang["files_upload_permissions_error"] = 'Problem med rettigheder. Mappen, som der uploades til, skal være skrivbar af webserveren.';
$_lang["files_uploadfile"] = 'Upload fil';
$_lang["files_uploadfile_msg"] = 'Vælg en fil til upload:';
Expand Down
7 changes: 7 additions & 0 deletions core/lang/de/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@
$_lang["files_upload_error5"] = 'Beim Upload ist ein Problem aufgetreten.';
$_lang["files_upload_inhibited_msg"] = '<b>Datei-Upload fehlgeschlagen.</b> Stellen Sie sicher, dass der Upload unterstützt wird und PHP in dieses Verzeichnis schreiben darf.';
$_lang["files_upload_ok"] = 'Upload erfolgreich!';
$_lang["files_upload_summary"] = '%1$s von %2$s Dateien hochgeladen.';
$_lang["files_upload_not_received"] = '%1$s Dateien haben den Server nicht erreicht: Er nimmt höchstens %2$s Dateien pro Upload an.';
$_lang["files_upload_zip_hint"] = 'Laden Sie sie erneut hoch oder packen Sie sie in eine ZIP-Datei, laden Sie diese hoch und entpacken Sie sie hier.';
$_lang["files_upload_progress"] = 'Dateien %1$s-%2$s von %3$s werden hochgeladen...';
$_lang["files_upload_details"] = 'Hochgeladene Dateien';
$_lang["files_upload_file_skipped"] = '„%1$s“ ist %2$s groß, eine Datei darf aber höchstens %3$s groß sein: Sie wurde nicht hochgeladen.';
$_lang["files_upload_stopped"] = 'Der Upload wurde abgebrochen (%1$s). Diese %2$s Dateien wurden nicht hochgeladen: %3$s';
$_lang["files_upload_permissions_error"] = 'Mögliche Probleme mit den Zugriffsrechten: das Upload-Verzeichnis muss auf dem Web-Server beschreibbar sein.';
$_lang["files_uploadfile"] = 'Datei hochladen';
$_lang["files_uploadfile_msg"] = 'Datei zum Hochladen wählen:';
Expand Down
7 changes: 7 additions & 0 deletions core/lang/en/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,13 @@
$_lang["files_upload_error5"] = 'There was a problem with your upload.';
$_lang["files_upload_inhibited_msg"] = '<b>Upload feature inhibited</b> - make sure uploads are supported and the directory is writable for PHP.';
$_lang["files_upload_ok"] = 'File uploaded successfully!';
$_lang["files_upload_summary"] = 'Uploaded %1$s of %2$s files.';
$_lang["files_upload_not_received"] = '%1$s files did not reach the server: it accepts at most %2$s files in one upload.';
$_lang["files_upload_zip_hint"] = 'Upload them again, or pack them into one ZIP file, upload it and unpack it here.';
$_lang["files_upload_progress"] = 'Uploading files %1$s-%2$s of %3$s...';
$_lang["files_upload_details"] = 'Uploaded files';
$_lang["files_upload_file_skipped"] = '"%1$s" is %2$s, but a file can be at most %3$s: it was not uploaded.';
$_lang["files_upload_stopped"] = 'The upload stopped (%1$s). These %2$s files were not uploaded: %3$s';
$_lang["files_upload_permissions_error"] = 'Possible permission problems - the directory you want to upload to needs to be writable by your webserver.';
$_lang["files_uploadfile"] = 'Upload file';
$_lang["files_uploadfile_msg"] = 'Select a file to upload:';
Expand Down
7 changes: 7 additions & 0 deletions core/lang/es/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@
$_lang["files_upload_error5"] = 'Hubo un problema con tu subida.';
$_lang["files_upload_inhibited_msg"] = '<b>Característica de subida deshabilitada</b> - asegúrate de que las subidas están soportadas y que el directorio es escribible por PHP.<br />';
$_lang["files_upload_ok"] = '¡Archivo subido con éxito!';
$_lang["files_upload_summary"] = 'Se subieron %1$s de %2$s archivos.';
$_lang["files_upload_not_received"] = '%1$s archivos no llegaron al servidor: acepta como máximo %2$s archivos por subida.';
$_lang["files_upload_zip_hint"] = 'Vuelve a subirlos, o empaquétalos en un solo archivo ZIP, súbelo y descomprímelo aquí.';
$_lang["files_upload_progress"] = 'Subiendo archivos %1$s-%2$s de %3$s...';
$_lang["files_upload_details"] = 'Archivos subidos';
$_lang["files_upload_file_skipped"] = '"%1$s" ocupa %2$s, pero un archivo puede ocupar como máximo %3$s: no se ha subido.';
$_lang["files_upload_stopped"] = 'La subida se detuvo (%1$s). Estos %2$s archivos no se subieron: %3$s';
$_lang["files_upload_permissions_error"] = 'Posibles problemas de permiso - el directorio al que quieres subir necesita ser escribible por tu servidor web.';
$_lang["files_uploadfile"] = 'Subir archivo';
$_lang["files_uploadfile_msg"] = 'Selecciona archivo a subir:';
Expand Down
Loading
Loading