Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
589 righe
24 KiB
589 righe
24 KiB
<? |
|
require_once $root."/inc/funzioni.php"; |
|
|
|
class filesManager { |
|
|
|
public static function extensionsArrayToRegex($extensions) { |
|
$extensions = implode("|",$extensions); |
|
$extensions = str_replace(".","",$extensions); |
|
$extensions = "/\.({$extensions})$/i"; |
|
return $extensions; |
|
} |
|
|
|
public static function acceptedFilesExtensions($format = "array") { |
|
$return = [".xml",".gif",".jpeg",".jpg",".png",".mp4",".mp3",".wav",".wmv",".txt",".csv",".CSV",".docx",".doc",".xlsx",".xls",".pptx",".ppt",".pdf",".rtf",".odt",".ods",".zip",".rar",".json",".7z",".p7m"]; |
|
if ($format == "regex") { |
|
$return = self::extensionsArrayToRegex($return); |
|
} |
|
return $return; |
|
} |
|
|
|
public static function tempDirUploadPath() { |
|
global $config; |
|
$folder = $config["chunk_folder"]; |
|
if(! empty($_SESSION["utente"]->codice)) { |
|
$folder .= "/{$_SESSION["utente"]->codice}"; |
|
} else { |
|
if(! empty($_SESSION["tmp_codice_utente"])) { |
|
$folder .= "/{$_SESSION["tmp_codice_utente"]}"; |
|
} else { |
|
$folder .= "/".session_id(); |
|
} |
|
} |
|
if (!file_exists($folder)) { |
|
mkdir($folder,0777,true); |
|
} |
|
return $folder; |
|
} |
|
|
|
public static function availableTypes() { |
|
|
|
return include "types.php"; |
|
|
|
} |
|
|
|
public static function insertResumableForm($onSuccessScript,string $uploaderID=null,array $options = []) { |
|
include __DIR__ . "/views/resumableUploader.php"; |
|
} |
|
|
|
public static function insertBlueImpForm($onSuccessScript,string $uploaderID=null,array $options = []) { |
|
include __DIR__ . "/views/blueImpUploader.php"; |
|
} |
|
|
|
public static function insertUploadForm($onSuccessScript,string $uploaderID=null,array $options = []) { |
|
global $__FilesManagerFormType; |
|
if (!isset($__FilesManagerFormType)) { |
|
$__FilesManagerFormType = "resumable"; |
|
} |
|
if ($__FilesManagerFormType == "blueimp") { |
|
self::insertBlueImpForm($onSuccessScript,$uploaderID,$options); |
|
} else if ($__FilesManagerFormType == "resumable") { |
|
self::insertResumableForm($onSuccessScript,$uploaderID,$options); |
|
} else { |
|
alertManager::printAlertBox(__("Errore inizializzazione uploader")); |
|
} |
|
} |
|
|
|
public static function printForm($id="", $tipo="A") { |
|
$modulo = modulo::getInfo(get_radice()); |
|
if (isset($_SESSION["utente"]) && !$_SESSION["utente"]->readOnly) { |
|
$formID = (is_numeric($id) ? $id : strtolower($id)) . '-'; |
|
if ($formID == "-") { |
|
$formID = ""; |
|
} |
|
ob_start(); |
|
?> |
|
$.ajax({ |
|
url: '/allegati/form.php', |
|
type: 'POST', |
|
dataType: 'json', |
|
data: {file: file.name, id: '<?= is_numeric($id) ? $id : strtolower($id) ?>', modulo: '<?= $modulo["id"] ?? null ?>'}, |
|
}) |
|
.done(function(file) { |
|
if('error' in file) { |
|
swal({ |
|
title: "Attenzione!", |
|
html: file.error + " Si prega di riprovare!", |
|
type: "warning", |
|
confirmButtonText: "Ok", |
|
confirmButtonClass: 'btn btn-warning', |
|
}); |
|
} else { |
|
if($('#<?= $formID ?>files-list').length > 0) { |
|
$('#<?= $formID ?>files-list').append(file.html); |
|
} |
|
f_ready(); |
|
} |
|
}) |
|
.fail(function() { |
|
swal({ |
|
title: "Attenzione!", |
|
text: "Si è verificato un errore nell'elaborazione del file. Si prega di riprovare!", |
|
type: "error", |
|
confirmButtonText: "Ok", |
|
confirmButtonClass: 'btn btn-danger', |
|
}); |
|
}); |
|
<? |
|
$successScript = ob_get_clean(); |
|
$allowedFileTypes = ($tipo=="M") ? ['.jpg','.jpeg','.png','.gif'] : ['.xml','.mp4','.mp3','.wav','.wmv','.txt','.doc','.docx','.xls','.xlsx','.ppt','.pptx','.pdf','.rtf','.odt','.ods','.zip','.rar','.7z','.jpg','.jpeg','.png','.csv','.gif','.p7m']; |
|
self::insertUploadForm($successScript,$formID,["allowedTypes"=>$allowedFileTypes]); |
|
?> |
|
<div id="<?= $formID ?>files-list"></div> |
|
<? |
|
} |
|
} |
|
|
|
public static function getAttachURL($allegato,$sourceID,$sourceType,$general_connection) { |
|
if (!empty($allegato) && isset(self::availableTypes()[$sourceType])) { |
|
$fileURL = "/allegati/open.php?codice={$allegato["codice"]}&filename=" . base64_encode($allegato["name"]) . "&sourceID={$sourceID}&sourceType=" . base64_encode($sourceType) . "&general_connection="; |
|
$fileURL .= ($general_connection) ? "1" : "0"; |
|
return $fileURL; |
|
} |
|
return false; |
|
} |
|
|
|
public static function printListWithLink($link = NULL,$sourceID,$sourceType,$tipo="A",$codici,$edit = true) { |
|
global $pdo; |
|
$return = false; |
|
$files = self::listFilesWithLink($link,$sourceID,$sourceType,$tipo,$codici); |
|
$general_connection = false; |
|
if(empty($link)) { |
|
$general_connection = true; |
|
} |
|
if (!empty($files)) { |
|
$return = true; |
|
if ($tipo=="A") { |
|
?> |
|
<table class="w-100 table table-striped table-hover mb-0"> |
|
<tbody id="list-attach-<?= $sourceID ?>-<?= $sourceType ?>-<?= $tipo ?>"> |
|
<? |
|
$categoria = $pdo->prepare("SELECT titolo FROM b_categorie_documentali WHERE codice = :codice"); |
|
foreach($files AS $allegato) { |
|
if(! empty($allegato["classificazione"])) { |
|
$categoria->bindValue(":codice", $allegato["classificazione"]); |
|
$categoria->execute(); |
|
$allegato["classificazione"] = $categoria->fetch(PDO::FETCH_COLUMN, 0); |
|
} |
|
$ext = strtolower(substr(strrchr($allegato["name"],"."),1)); |
|
switch ($ext) { |
|
case 'rar': |
|
case 'zip': |
|
$fa = 'fa-file-archive'; |
|
break; |
|
case 'xsl': |
|
case 'xslx': |
|
case 'ods': |
|
$fa = 'fa-file-excel'; |
|
break; |
|
case 'doc': |
|
case 'docx': |
|
$fa = 'fa-file-word'; |
|
break; |
|
case 'odt': |
|
$fa = 'fa-file-alt'; |
|
break; |
|
case 'pdf': |
|
$fa = 'fa-file-pdf'; |
|
break; |
|
default: |
|
$fa = 'fa-file'; |
|
break; |
|
} |
|
$fileURL = self::getAttachURL($allegato,$sourceID,$sourceType,$general_connection); |
|
?> |
|
<tr class="allegato" id="allegato-<? echo $allegato["codice"] ?>"> |
|
<? if ($edit) { ?> |
|
<td width="1" class="handle"> |
|
<input class="ordinamento" type="hidden" name="ordinamento-files[<?= $allegato["codice"] ?>]" value="<?= $allegato["ordinamento"] ?>"> |
|
<em class="fa fa-bars"></em> |
|
</td> |
|
<? } ?> |
|
<td width="10"> |
|
<em class="fa <?= $fa ?>"></em> |
|
</td> |
|
<td class="text-break"> |
|
<a target="_blank" href="<?= $fileURL ?>"><?= $allegato["titolo"] ?></a><br> |
|
<small>SHA-256: <?= $allegato["sha256"] ?></small><br> |
|
<small> |
|
<? if (! empty($allegato["classificazione"]) && strpos($_SERVER["PHP_SELF"], "backend") !== false) : ?> |
|
<span class="badge badge-secondary mr-2"><?= $allegato["classificazione"] ?></span> |
|
<? endif; ?> |
|
<?= mysql2datetime($allegato["timestamp"]) ?> |
|
</small> |
|
</td> |
|
<td width="100"> |
|
<?= human_filesize($allegato["size"]) ?> |
|
</td> |
|
<? if ($edit) { ?> |
|
<? |
|
$type = self::availableTypes()[$sourceType]; |
|
$switch = $type["switch"] ?? null; |
|
if (!empty($switch)) { |
|
?> |
|
<td> |
|
<button class="float-right btn btn-sm btn-primary" title="<?= __('Attiva/Disattiva') ?>" onClick="confirmBeforeSubmit('<?= $allegato["codice"] ?>','/allegati/switch.php','sourceType=<?= $sourceType ?>&general_connection=<?= ($general_connection) ? "1" : "0" ?>'); return false;"> |
|
<span class="fa fa-<?= $type["type"] == "reserved" ? "unlock" : "lock" ?>"></span> |
|
</button> |
|
</td> |
|
<? |
|
} |
|
?> |
|
<td width="10"> |
|
<button class="float-right btn btn-sm btn-danger" title="<?= __('Elimina') ?>" onClick="eliminaP('<?= $allegato["codice"] ?>','allegati','sourceType=<?= $sourceType ?>&general_connection=<?= ($general_connection) ? "1" : "0" ?>'); return false;"> |
|
<span class="fa fa-trash-alt"></span> |
|
</button> |
|
</td> |
|
<? } ?> |
|
</tr> |
|
<? |
|
} |
|
?> |
|
</tbody> |
|
</table> |
|
<? |
|
} else { ?> |
|
<div class="card mb-1"> |
|
<div class="card-body"> |
|
<div class="row" id="list-attach-<?= $sourceID ?>-<?= $sourceType ?>-<?= $tipo ?>"> |
|
<? |
|
foreach($files AS $allegato) { |
|
$fileURL = self::getAttachURL($allegato,$sourceID,$sourceType,$general_connection); |
|
?> |
|
<div class="allegato col-4 col-sm-3 col-md-2 text-center" id="allegato-<? echo $allegato["codice"] ?>"> |
|
<a href="<?= $fileURL ?>" data-lightbox="lb-<?= $sourceID ?>-<?= $sourceType ?>-<?= $tipo ?>" data-title="<?= $allegato["titolo"]; ?>"> |
|
<img class="handle thumbnail" style="width:100%" src="<?= $fileURL ?>&thumbnail=true" alt="<?= $allegato["titolo"] ?> - thumbnail"> |
|
</a> |
|
<? if ($edit) { ?> |
|
<input class="ordinamento" type="hidden" name="ordinamento-files[<?= $allegato["codice"] ?>]" value="<?= $allegato["ordinamento"] ?>"> |
|
<button class="btn btn-sm btn-danger tile-tools" title="<?= __('Elimina') ?>" onClick="eliminaP('<?= $allegato["codice"] ?>','allegati','sourceType=<?= $sourceType ?>&general_connection=<?= ($general_connection) ? "1" : "0" ?>'); return false;"> |
|
<span class="fa fa-times"></span> |
|
</button> |
|
<? } ?> |
|
</div> |
|
<? } ?> |
|
</div> |
|
</div> |
|
</div> |
|
<? } |
|
if ($edit) { ?> |
|
<script> |
|
$( "#list-attach-<?= $sourceID ?>-<?= $sourceType ?>-<?= $tipo ?>" ).sortable({ |
|
handle: ".handle", |
|
update: function( event, ui ) { |
|
$(".allegato","#list-attach-<?= $sourceID ?>-<?= $sourceType ?>-<?= $tipo ?>").each(function(index, el) { |
|
$(this).find('.ordinamento').val(index); |
|
}); |
|
$.ajax({ |
|
type: "POST", |
|
url: '/allegati/save-order.php?general_connection=<?= ($general_connection) ? "1" : "0" ?>', |
|
data: $('.ordinamento').serialize(), |
|
async: true |
|
}); |
|
} |
|
}); |
|
</script> |
|
<? |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public static function verifyPermission($sourceType,$sourceID,$operation = "LIST",$allegato = []) { |
|
$types = self::availableTypes(); |
|
if (isset($types[$sourceType])) { |
|
if(defined("__CMDS_JOB_EXEC")) { |
|
return true; |
|
} |
|
$type = $types[$sourceType]; |
|
$save = false; |
|
if ($operation != "LIST") { $save = true; } |
|
|
|
if (!empty($sourceID) && !empty($sourceType) && (!empty($_SESSION["utente"]->codice) || ($type["type"]=="public" && !$save))) { |
|
global $pdo; |
|
global $root; |
|
global $config; |
|
$return = !$save; |
|
if (!empty($type["script"]) && ($type["type"]!="public" || $save)) { |
|
$return = false; |
|
if (!empty($type["setId"])) { |
|
$id = $sourceID; |
|
$modulo = $type["modulo"]; |
|
} |
|
include($root.$type["script"]); |
|
} |
|
return $return; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public static function getTable($sourceType) { |
|
$types = self::availableTypes(); |
|
if (isset($types[$sourceType])) { |
|
if (!empty($types[$sourceType]["generalFolder"])) { |
|
return "b_mainFileManager"; |
|
} else { |
|
return "b_fileManager"; |
|
} |
|
} |
|
} |
|
|
|
public static function deleteFileWithLink($link = null,$codice,$sourceType) { |
|
$environmentFolder = 0; |
|
$return = true; |
|
global $pdo; |
|
global $config; |
|
$table = self::getTable($sourceType); |
|
if (!empty($table)) { |
|
if (isset($_SESSION["ente"]->codice) && $table == "b_fileManager") { |
|
$environmentFolder = $_SESSION["ente"]->codice; |
|
} |
|
$bind = array(":codice"=>$codice); |
|
$sql = "SELECT * FROM {$table} WHERE codice = :codice "; |
|
$ris = $pdo->go($sql,$bind); |
|
if ($ris->rowCount() === 1) { |
|
$allegato = $ris->fetch(PDO::FETCH_ASSOC); |
|
$path = $config["mediaFolder"] . "/{$environmentFolder}/{$allegato["sourceType"]}/{$allegato["sourceID"]}/" . md5($allegato["content"]).$allegato["sha256"]; |
|
$path_mv = $config["mediaFolder"] . "/_del/{$environmentFolder}_{$allegato["codice"]}_{$allegato["sourceType"]}_{$allegato["sourceID"]}_" . md5($allegato["content"]).$allegato["sha256"]; |
|
$permission = filesManager::verifyPermission($allegato["sourceType"],$allegato["sourceID"],"DELETE",$allegato); |
|
if ($permission) { |
|
$bind = array(":codice"=>$codice); |
|
$sql = "UPDATE {$table} SET soft_delete = 'S' WHERE codice = :codice "; |
|
$ris = $pdo->go($sql,$bind); |
|
if ($ris->rowCount() === 1) { |
|
$return = true; |
|
scriviLog($table,"DELETE",$pdo->getSQL(),$_POST["codice"]); |
|
if (file_exists($path)) { |
|
if (!is_dir($config["mediaFolder"] . "/_del")) { mkdir($config["mediaFolder"] . "/_del",0750,true); } |
|
rename($path,$path_mv); |
|
touch($path_mv); |
|
if (file_exists($path."_thumb")) { |
|
rename($path."_thumb",$path_mv."_thumb"); |
|
touch($path_mv."_thumb"); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} else { |
|
$return = false; |
|
} |
|
return $return; |
|
} |
|
|
|
public static function deleteFile($codice,$sourceType) { |
|
return self::deleteFileWithLink(NULL,$codice,$sourceType); |
|
} |
|
|
|
public static function switchFileWithLink($link = null,$codice,$sourceType) { |
|
$environmentFolder = 0; |
|
$return = true; |
|
global $pdo; |
|
global $config; |
|
$table = self::getTable($sourceType); |
|
$type = self::availableTypes()[$sourceType]; |
|
if (!empty($table) && !empty($type["switch"])) { |
|
if (isset($_SESSION["ente"]->codice) && $table == "b_fileManager") { |
|
$environmentFolder = $_SESSION["ente"]->codice; |
|
} |
|
$bind = array(":codice"=>$codice); |
|
$sql = "SELECT * FROM {$table} WHERE codice = :codice "; |
|
$ris = $pdo->go($sql,$bind); |
|
if ($ris->rowCount() === 1) { |
|
$allegato = $ris->fetch(PDO::FETCH_ASSOC); |
|
$path = $config["mediaFolder"] . "/{$environmentFolder}/{$allegato["sourceType"]}/{$allegato["sourceID"]}/" . md5($allegato["content"]).$allegato["sha256"]; |
|
$path_mv = $config["mediaFolder"] . "/{$environmentFolder}/{$type["switch"]}/{$allegato["sourceID"]}/" . md5($allegato["content"]).$allegato["sha256"]; |
|
$permission = filesManager::verifyPermission($allegato["sourceType"],$allegato["sourceID"],"SWITCH",$allegato); |
|
if ($permission) { |
|
$bind = array(":codice"=>$codice,":dest"=>$type["switch"]); |
|
$sql = "UPDATE {$table} SET sourceType = :dest WHERE codice = :codice "; |
|
$ris = $pdo->go($sql,$bind); |
|
if ($ris->rowCount() === 1) { |
|
$return = true; |
|
scriviLog($table,"SWITCH",$pdo->getSQL(),$_POST["codice"]); |
|
if (file_exists($path)) { |
|
if (!is_dir($config["mediaFolder"] . "/{$environmentFolder}/{$type["switch"]}/{$allegato["sourceID"]}")) { mkdir($config["mediaFolder"] . "/{$environmentFolder}/{$type["switch"]}/{$allegato["sourceID"]}",0750,true); } |
|
rename($path,$path_mv); |
|
touch($path_mv); |
|
if (file_exists($path."_thumb")) { |
|
rename($path."_thumb",$path_mv."_thumb"); |
|
touch($path_mv."_thumb"); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} else { |
|
$return = false; |
|
} |
|
return $return; |
|
} |
|
|
|
public static function switchFile($codice,$sourceType) { |
|
return self::switchFileWithLink(NULL,$codice,$sourceType); |
|
} |
|
|
|
public static function getFilePathFromAttachmentRecord(Array $allegato) |
|
{ |
|
global $config; |
|
$environmentFolder = 0; |
|
$type = self::availableTypes()[$allegato["sourceType"]]; |
|
if (isset($_SESSION["ente"]) && empty($type["generalFolder"])) { $environmentFolder = $_SESSION["ente"]->codice; } |
|
return "{$config["mediaFolder"]}/{$environmentFolder}/{$allegato["sourceType"]}/{$allegato["sourceID"]}/" . md5($allegato["content"]) . $allegato["sha256"]; |
|
} |
|
|
|
public static function listFilesWithLink($link = NULL,$sourceID,$sourceType,$tipo="A",$codici=0) { |
|
$return = false; |
|
if (self::verifyPermission($sourceType,$sourceID)) { |
|
global $pdo, $root; |
|
if (empty($link)) { |
|
$link = $pdo; |
|
} |
|
$table = self::getTable($sourceType); |
|
if (!empty($table)) { |
|
$sql = "SELECT * FROM $table WHERE sourceID = :sourceID AND sourceType = :sourceType AND tipo = :tipo AND soft_delete = 'N' "; |
|
if (!empty($codici) && is_array($codici)) { |
|
$tmp = []; |
|
foreach($codici AS $cod) { |
|
if (is_numeric($cod)) { |
|
$tmp[] = (int)$cod; |
|
} |
|
} |
|
if (!empty($tmp)) { |
|
$sql .= " AND codice IN ("; |
|
$sql .= implode(",",$tmp); |
|
$sql .= ")"; |
|
} |
|
} |
|
$sql .= " ORDER BY ordinamento, codice "; |
|
$ris = $link->go($sql,array(":sourceID" => $sourceID,":sourceType"=>$sourceType, ":tipo"=>$tipo)); |
|
if ($ris->rowCount() > 0) { |
|
$return = $ris->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public static function printlist($sourceID,$sourceType,$tipo="A",$codici=0,$edit = true) { |
|
return self::printListWithLink(NULL, $sourceID,$sourceType,$tipo,$codici,$edit); |
|
} |
|
|
|
public static function listFiles($sourceID,$sourceType,$tipo="A",$codici=0) { |
|
return self::listFilesWithLink(NULL, $sourceID,$sourceType,$tipo,$codici); |
|
} |
|
|
|
public static function saveFile($filename,$sourceID,$sourceType,$titolo = "",$tipo="A",$classificazione="") { |
|
return self::saveFileWithLink(NULL, $filename,$sourceID,$sourceType,$titolo,$tipo,$classificazione); |
|
} |
|
|
|
public static function saveFileFromBuffer($link = NULL,$content,$sourceID,$sourceType,$titolo="",$tipo="A") { |
|
$return = false; |
|
if (!empty($content)) { |
|
if (self::verifyPermission($sourceType,$sourceID,"SAVE")) { |
|
global $config; |
|
$filename = time().$sourceID.$sourceType; |
|
$path = $config["chunk_folder"]."/".($_SESSION["utente"]->codice); |
|
if (!is_dir($path)) { |
|
mkdir($path); |
|
} |
|
$path .= "/".$filename; |
|
if (file_put_contents($path,$content)) { |
|
$return = self::saveFileWithLink($link,$filename,$sourceID,$sourceType,$titolo,$tipo); |
|
} |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public static function saveFileWithLink($link = NULL,$filename,$sourceID,$sourceType,$titolo = "",$tipo="A",$classificazione="") { |
|
$return = false; |
|
if (self::verifyPermission($sourceType,$sourceID,"SAVE")) { |
|
global $root, $config, $pdo; |
|
$type = self::availableTypes()[$sourceType]; |
|
if(empty($link)) { |
|
$link = $pdo; |
|
$environmentFolder = 0; |
|
} |
|
if (isset($_SESSION["ente"]) && empty($type["generalFolder"])) { |
|
$environmentFolder = $_SESSION["ente"]->codice; |
|
} |
|
$table = self::getTable($sourceType); |
|
if (!empty($table)) { |
|
$path = $config["chunk_folder"]."/".($_SESSION["utente"]->codice)."/".$filename; |
|
if (file_exists($path)) { |
|
adaptMemoryLimitToFile($path); |
|
$file = array(); |
|
$file_info = new finfo(FILEINFO_MIME_TYPE); |
|
$file["mime"] = $file_info->file($path); |
|
$file["size"] = filesize($path); |
|
$file["codice_ente"] = $environmentFolder; |
|
$content = file_get_contents($path); |
|
$file["content"] = generateStrongPassword(); |
|
$file["md5"] = hash("md5",$content); |
|
$file["sha1"] = hash("sha1",$content); |
|
$file["sha256"] = hash("sha256",$content); |
|
$file["name"] = sanitize_string($filename); |
|
$file["titolo"] = htmlentities($titolo); |
|
$file["sourceID"] = $sourceID; |
|
$file["sourceType"] = $sourceType; |
|
$file["classificazione"] = $classificazione; |
|
$file["tipo"] = $tipo; |
|
$destPath = "{$config["mediaFolder"]}/{$environmentFolder}/{$sourceType}/{$sourceID}/"; |
|
if (!is_dir($destPath)) { mkdir($destPath,0750,true); } |
|
$destPath .= md5($file["content"]).$file["sha256"]; |
|
if ($tipo=="M") { |
|
$image = new \claviska\SimpleImage($path); |
|
$image->autoOrient(); |
|
$image->bestFit(1170,1170); |
|
$content = $image->toString(); |
|
unset($image); |
|
$image = new \claviska\SimpleImage($path); |
|
$image->autoOrient(); |
|
$image->thumbnail(200,200); |
|
$content_thumb = $image->toString(); |
|
} |
|
|
|
$content = simple_encrypt($content,$file["content"]); |
|
file_put_contents($destPath, $content); |
|
if (file_exists($destPath)) { |
|
if (isset($content_thumb)) { |
|
$content_thumb = simple_encrypt($content_thumb,$file["content"]); |
|
file_put_contents($destPath."_thumb", $content_thumb); |
|
} |
|
$salva = new salva($link); |
|
$salva->debug = false; |
|
$salva->nome_tabella = $table; |
|
$salva->operazione = "INSERT"; |
|
$salva->oggetto = $file; |
|
$return = $salva->save(); |
|
} |
|
unlink($path); |
|
} |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public static function fileInfo($codice,$filename,$sourceID,$sourceType,$decrypt=false) { |
|
return self::fileInfoWithLink(NULL,$codice,$filename,$sourceID,$sourceType,$decrypt); |
|
} |
|
|
|
public static function fileInfoWithLink($link=NULL,$codice,$filename,$sourceID,$sourceType,$decrypt=false) { |
|
$return = false; |
|
|
|
if (self::verifyPermission($sourceType,$sourceID)) { |
|
global $pdo, $config; |
|
$environmentFolder = 0; |
|
$type = self::availableTypes()[$sourceType]; |
|
if (isset($_SESSION["ente"]) && empty($type["generalFolder"])) { $environmentFolder = $_SESSION["ente"]->codice; } |
|
if (empty($link)) { $link = $pdo; } |
|
$table = self::getTable($sourceType); |
|
if (!empty($table)) { |
|
$sql = "SELECT * FROM {$table} WHERE codice = :codice AND name = :filename AND sourceID = :sourceID AND sourceType = :sourceType AND soft_delete = 'N'"; |
|
$ris = $link->go($sql,array(":codice" => $codice,":filename" => $filename,":sourceID" => $sourceID,":sourceType"=>$sourceType)); |
|
if ($ris->rowCount() === 1) { |
|
$return = $ris->fetch(PDO::FETCH_ASSOC); |
|
if ($decrypt) { |
|
$path = $config["mediaFolder"] . "/{$environmentFolder}/{$return["sourceType"]}/{$return["sourceID"]}/" . md5($return["content"]).$return["sha256"]; |
|
if ($return["tipo"]=="M" && !empty($_GET["thumbnail"])) { $path .= "_thumb"; } |
|
if (file_exists($path)) { |
|
adaptMemoryLimitToFile($path); |
|
$content = file_get_contents($path); |
|
$return["content"] = simple_decrypt($content, $return["content"]); |
|
if (empty($return["content"])) { |
|
$return = false; |
|
} |
|
} else { |
|
$return = false; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return $return; |
|
} |
|
} |
|
|
|
?>
|
|
|