mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02: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:
16
actions.php
16
actions.php
@ -15,12 +15,12 @@ if (!empty($id_plugin)) {
|
|||||||
$permesso = $id_module;
|
$permesso = $id_module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$upload_dir = $docroot.'/files/'.basename($directory);
|
||||||
|
|
||||||
$dbo->query('START TRANSACTION');
|
$dbo->query('START TRANSACTION');
|
||||||
|
|
||||||
// GESTIONE UPLOAD
|
// GESTIONE UPLOAD
|
||||||
if (filter('op') == 'link_file' || filter('op') == 'unlink_file') {
|
if (filter('op') == 'link_file' || filter('op') == 'unlink_file') {
|
||||||
$upload_dir = $docroot.'/files/'.basename($directory);
|
|
||||||
|
|
||||||
// Controllo sui permessi di scrittura per il modulo
|
// Controllo sui permessi di scrittura per il modulo
|
||||||
if (Modules::getPermission($id_module) != 'rw') {
|
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_'));
|
$_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
|
// Creazione file fisico
|
||||||
if (move_uploaded_file($src, $upload_dir.'/'.$filename)) {
|
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!');
|
$_SESSION['infos'][] = _('File caricato correttamente!');
|
||||||
} else {
|
} 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);
|
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') {
|
if (Modules::getPermission($permesso) == 'rw') {
|
||||||
|
@ -35,7 +35,7 @@ class FileManager implements ManagerInterface
|
|||||||
<tr>
|
<tr>
|
||||||
<th>'._('Nome').'</th>
|
<th>'._('Nome').'</th>
|
||||||
<th>'._('Data').'</th>
|
<th>'._('Data').'</th>
|
||||||
<th style="width:5%;text-align:center;">#</th>
|
<th width="10%" class="text-center">#</th>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
foreach ($rs as $r) {
|
foreach ($rs as $r) {
|
||||||
@ -47,7 +47,11 @@ class FileManager implements ManagerInterface
|
|||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>'.\Translator::timestampToLocale($r['created_at']).'</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'].'">
|
<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>
|
<i class="fa fa-trash"></i>
|
||||||
</a>
|
</a>
|
||||||
|
@ -227,6 +227,10 @@ if (!function_exists('force_download')) {
|
|||||||
header('Content-Transfer-Encoding: binary');
|
header('Content-Transfer-Encoding: binary');
|
||||||
|
|
||||||
if ($content) {
|
if ($content) {
|
||||||
|
if (is_file($content)) {
|
||||||
|
$content = file_get_contents($content);
|
||||||
|
}
|
||||||
|
|
||||||
header('Content-Length: '.strlen($content));
|
header('Content-Length: '.strlen($content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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';
|
ALTER TABLE `zz_logs` CHANGE `timestamp` `timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00';
|
||||||
|
|
||||||
-- Adeguamento dei contenuti di zz_files
|
-- 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`);
|
UPDATE `zz_files` SET `id_module` = (SELECT `id` FROM `zz_modules` WHERE `zz_modules`.`directory` = `zz_files`.`module`);
|
||||||
ALTER TABLE `zz_files` DROP `module`;
|
ALTER TABLE `zz_files` DROP `module`;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user