.
*/
include_once __DIR__.'/core.php';
$file_id = filter('file_id');
$file = Models\Upload::find($file_id);
if (empty($file)) {
return;
}
$file_content = $file->get_contents();
// Force download of the file
if (get('download') == '1') {
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: Binary');
header('Content-disposition: attachment; filename="'.basename($file->original_name).'"');
echo $file_content;
exit;
}
// Force preview of the file
if (get('preview') == '1') {
if ($file->isImage()) {
$finfo = finfo_open();
$mime_type = finfo_buffer($finfo, $file_content, FILEINFO_MIME_TYPE);
finfo_close($finfo);
header('Content-Type: '.$mime_type);
echo $file_content;
} elseif ($file->isPDF()) {
header("Content-type: application/pdf");
echo $file_content;
}
exit;
}
if ($file->isFatturaElettronica()) {
// Individuazione stylesheet
$default_stylesheet = 'asso-invoice';
$name = basename($file->original_name);
$filename = explode('.', $name)[0];
$pieces = explode('_', $filename);
$stylesheet = $pieces[2];
$stylesheet = base_dir().'/plugins/xml/'.$stylesheet.'.xsl';
$stylesheet = file_exists($stylesheet) ? $stylesheet : base_dir().'/plugins/xml/'.$default_stylesheet.'.xsl';
// XML
$xml = new DOMDocument();
$xml->loadXML($file_content);
// XSL
$xsl = new DOMDocument();
$xsl->load($stylesheet);
// XSLT
$xslt = new XSLTProcessor();
$xslt->importStylesheet($xsl);
echo '
';
echo $xslt->transformToXML($xml);
} else {
echo '
';
if ($file->isImage()) {
echo '
';
} elseif ($file->isPDF()) {
echo '
';
} else {
echo '
';
}
}