Skip to content

Instantly share code, notes, and snippets.

@scriptdev
Last active April 20, 2024 01:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptdev/4e783fb69ae95f268b1046f618bce5c7 to your computer and use it in GitHub Desktop.
Save scriptdev/4e783fb69ae95f268b1046f618bce5c7 to your computer and use it in GitHub Desktop.
LINK DOWNLOAD DO ARQUIVO NO DATAGRID
<?php
/*
COMPONENTE : TFile
TIPO DE GRAVAÇÃO : Armazenar o conteúdo e nome do arquivo na tabela
COLUNA PARA ARMAZENAR OS DADOS : campo: base64_dados
COLUNA PARA ARMAZENAR O NOME DO ARQUIVO : campo: nome_arquivo
*/
$column_conteudo_arquivo_transformed->setTransformer(function($value, $object, $row)
{
$action = new TAction(['DocumentoList', 'baixarDocumento'], ['key' => $object->id]);
$a = new TElement('a');
$a->class = 'btn btn-link';
$a->generator = 'adianti';
$a->href = $action->serialize();
$a->add($object->nome_arquivo);
return $a;
});
# MÉTODO DO FORMULÁRIO
public static function baixarDocumento($param = [])
{
try
{
TTransaction::open(self::$database);
$anexosCliente = new AnexosCliente($param['key']);
$caminho_arquivo = "tmp/{$anexosCliente->nome_arquivo}";
if(!is_file($caminho_arquivo))
{
file_put_contents($caminho_arquivo, base64_decode($anexosCliente->conteudo_arquivo));
}
TTransaction::close();
TPage::openFile($caminho_arquivo);
}
catch (Exception $e)
{
new TMessage('error', $e->getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment