AjaxForm отображение загруженных файлов в адмике

Подскажите пжта, как реализовать возможность просмотра файлов, прикрепленных к форме, непосредственно в Formit? Сейчас в Formit отображается только наименование файла. Файлы успешно сохраняются на сервере, но открыть их через Formit не получается.
Сам вызов формы:
[[!AjaxForm?
&snippet=`FormIt`
&form=`tpl.AjaxForm.template`
&hooks=`formit2file,FormItSaveForm,email`
&customValidators=`formit2checkfile`
&emailTpl=`tpl.email`
&formName=`JOB FROM SITE` &formFields=`name,age,message,upload_1`
&fieldNames=`name==Name,age==Age,message==About me,upload==Photo №1`
&validationErrorMessage=`The form contains errors!`
&successMessage=`Message sent successfully!`
&closeMessage=`Close message`
&errTpl=`[[+error]]`
]]
Загрузка файлов посредством сниппета formit2file:
<?php
// initialize output;
$output = true;
  
// valid extensions
$ext_array = array('jpg', 'jpeg', 'png');
  
// create unique path for this form submission
//$uploadpath = 'assets/uploads/';
  
// you can create some logic to automatically
// generate some type of folder structure here.
// the path that you specify will automatically
// be created by the script if it doesn't already
// exist.
  
// EXAMPLE:
// this would put all file uploads into a new,
// unique folder every day.
$uploadpath = 'assets/uploads/'.date('Y-m-d').'/';
  
// get full path to unique folder
$target_path = $modx->config['base_path'] . $uploadpath;
  
// get uploaded file names:
$submittedfiles = array_keys($_FILES);
  
// loop through files
foreach ($submittedfiles as $sf) {
  
    // Get Filename and make sure its good.
    $filename = basename( $_FILES[$sf]['name'] );
  
    // Get file's extension
    $ext = pathinfo($filename, PATHINFO_EXTENSION);
    $ext = mb_strtolower($ext); // case insensitive
  
    // is the file name empty (no file uploaded)
    if($filename != '') {
          
        // is this the right type of file?
        if(in_array($ext, $ext_array)) {
      
            // clean up file name and make unique
            $filename = mb_strtolower($filename); // to lowercase
            $filename = str_replace(' ', '_', $filename); // spaces to underscores
            //$filename = date("Y-m-d_G-i-s_") . $filename; // add date & time
              
            // full path to new file
            $myTarget = $target_path . $filename;
              
            // create directory to move file into if it doesn't exist
            if(!is_dir($target_path)) {
                mkdir($target_path, 0755, true);
                } else {
                $modx->log(modX::LOG_LEVEL_ERROR, 'dossier existe' );    
                }
              
            // is the file moved to the proper folder successfully?
            if(move_uploaded_file($_FILES[$sf]['tmp_name'], $myTarget)) {
                // set a new placeholder with the new full path (if you need it in subsequent hooks)
                $modx->setPlaceholder('fi.'.$sf.'_new', $myTarget);
                // set the permissions on the file
                if (!chmod($myTarget, 0644)) { /*some debug function*/ }
                  
            } else {
                // File not uploaded
                $errorMsg = 'There was a problem uploading the file.';
                $hook->addError($sf, $errorMsg);
                $output = false; // generate submission error
            }
          
        } else {
            // File type not allowed
            $errorMsg = 'Type of file not allowed.';
            $hook->addError($sf, $errorMsg);
            $output = false; // generate submission error
        }
      
    // if no file, don't error, but return blank
    } else {
        $hook->setValue($sf, '');
    }
  
}
  
return $output;
Антон
05 апреля 2020, 19:00
modx.pro
593
0

Комментарии: 2

Баха Волков
06 апреля 2020, 22:23
0
Для этого нужно написать плагин, штатными средствами сделать не получится
    Максим
    07 апреля 2020, 09:05
    0
    Может это поможет: modx.pro/solutions/14568
      Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
      2