function execute(&$form, $action_id) { $config = !empty($form->actions_config[$action_id]) ? $form->actions_config[$action_id] : array(); $config = new \GCore\Libs\Parameter($config); $file_path = $config->get('path'); if (\GCore\Libs\File::exists($file_path)) { \GCore\Libs\Download::send($file_path); } }
public static function on_finalize($controller) { $config = new \GCore\Libs\Parameter($controller->connection['Connection']['extras']['plugins']['download']); $path_field = $config->get('path_field'); $download_action = $config->get('download_action'); if (!empty($path_field) and !empty($download_action)) { if ($controller->action == $download_action) { if (!empty($controller->data['gcb'])) { $path_pcs = explode('.', $path_field); $field = array_pop($path_pcs); $model = array_pop($path_pcs); $row = $controller->connection_models[$model]->load($controller->data['gcb']); if (!empty($row)) { $file_path = \GCore\Libs\Arr::getVal($row, explode('.', $path_field)); if ($config->get('download_path')) { $file_path = rtrim($config->get('download_path'), DS) . DS . $file_path; } if (is_dir($file_path)) { //this is a folder $files = @\GCore\Libs\Folder::getFiles($file_path, false); foreach ($files as $file) { $found[$file] = filemtime($file); } if (empty($found)) { return false; } arsort($found); $files = array_keys($found); sort($files); $file = array_pop($files); \GCore\Libs\Download::send($file, 'D'); } else { //this is a file $file = $file_path; \GCore\Libs\Download::send($file, 'D'); } } } } } }