1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-22 21:28:08 +01:00

Pulsante di download per i file

Aggiunto pulsante di download per i file, con scaricamento del contenuto con il nome originale.
This commit is contained in:
Thomas Zilio 2017-08-28 09:49:38 +02:00
parent d47fbd3fcc
commit f167ab1e47
4 changed files with 24 additions and 6 deletions

View File

@ -15,12 +15,12 @@ if (!empty($id_plugin)) {
$permesso = $id_module;
}
$upload_dir = $docroot.'/files/'.basename($directory);
$dbo->query('START TRANSACTION');
// GESTIONE UPLOAD
if (filter('op') == 'link_file' || filter('op') == 'unlink_file') {
$upload_dir = $docroot.'/files/'.basename($directory);
// Controllo sui permessi di scrittura per il modulo
if (Modules::getPermission($id_module) != 'rw') {
$_SESSION['errors'][] = str_replace('_MODULE_', '"'.Modules::getModule($id_module)['name'].'"', _('Non hai permessi di scrittura per il modulo _MODULE_'));
@ -163,7 +163,13 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') {
// Creazione file fisico
if (move_uploaded_file($src, $upload_dir.'/'.$filename)) {
$dbo->query('INSERT INTO `zz_files`(nome, filename, id_module, id_record) VALUES('.prepare($nome).', '.prepare($filename).', '.prepare($id_module).', '.prepare($id_record).')');
$dbo->insert('zz_files', [
'nome' => $nome,
'filename' => $filename,
'original' => $_FILES['blob']['name'],
'id_module' => $id_module,
'id_record' => $id_record,
]);
$_SESSION['infos'][] = _('File caricato correttamente!');
} else {
@ -194,6 +200,10 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') {
redirect(ROOTDIR.'/editor.php?id_module='.$id_module.'&id_record='.$id_record);
}
} elseif (filter('op') == 'download_file') {
$rs = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module='.prepare($id_module).' AND id='.prepare(filter('id')).' AND filename='.prepare(filter('filename')));
force_download($rs[0]['original'], $upload_dir.'/'.$rs[0]['filename']);
}
if (Modules::getPermission($permesso) == 'rw') {

View File

@ -35,7 +35,7 @@ class FileManager implements ManagerInterface
<tr>
<th>'._('Nome').'</th>
<th>'._('Data').'</th>
<th style="width:5%;text-align:center;">#</th>
<th width="10%" class="text-center">#</th>
</tr>';
foreach ($rs as $r) {
@ -47,7 +47,11 @@ class FileManager implements ManagerInterface
</a>
</td>
<td>'.\Translator::timestampToLocale($r['created_at']).'</td>
<td>
<td class="text-center">
<a class="btn btn-primary" href="'.ROOTDIR.'/actions.php?id_module='.$options['id_module'].'&op=download_file&id='.$r['id'].'&filename='.$r['filename'].'" target="_blank">
<i class="fa fa-download"></i>
</a>
<a class="btn btn-danger ask" data-backto="record-edit" data-msg="'._('Vuoi eliminare questo file?').'" data-op="unlink_file" data-id="'.$r['id'].'" data-filename="'.$r['filename'].'">
<i class="fa fa-trash"></i>
</a>

View File

@ -227,6 +227,10 @@ if (!function_exists('force_download')) {
header('Content-Transfer-Encoding: binary');
if ($content) {
if (is_file($content)) {
$content = file_get_contents($content);
}
header('Content-Length: '.strlen($content));
}

View File

@ -686,7 +686,7 @@ ALTER TABLE `my_impianto_componenti` ADD FOREIGN KEY (`idsostituto`) REFERENCES
ALTER TABLE `zz_logs` CHANGE `timestamp` `timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00';
-- Adeguamento dei contenuti di zz_files
ALTER TABLE `zz_files` CHANGE `externalid` `id_record` int(11) NOT NULL, ADD `id_module` int(11) NOT NULL AFTER `filename`;
ALTER TABLE `zz_files` CHANGE `externalid` `id_record` int(11) NOT NULL, ADD `id_module` int(11) NOT NULL AFTER `filename`, ADD `original` varchar(255) NOT NULL AFTER `filename`;
UPDATE `zz_files` SET `id_module` = (SELECT `id` FROM `zz_modules` WHERE `zz_modules`.`directory` = `zz_files`.`module`);
ALTER TABLE `zz_files` DROP `module`;