From f53559eef164de5f4775f3fc260af4ef6ac1dc0f Mon Sep 17 00:00:00 2001 From: Matteo Date: Tue, 19 Mar 2024 13:23:08 +0100 Subject: [PATCH] Introduzione connettori per il caricamento dei file --- actions.php | 20 +- composer.json | 3 + modules/adattatori_archiviazione/actions.php | 58 +++++ modules/adattatori_archiviazione/add.php | 43 ++++ modules/adattatori_archiviazione/edit.php | 64 +++++ modules/adattatori_archiviazione/init.php | 28 +++ .../src/Adapters/FTPAdapter.php | 34 +++ .../src/Adapters/LocalAdapter.php | 33 +++ .../src/FileAdapter.php | 61 +++++ .../src/OSMFilesystem.php | 73 ++++++ modules/import/actions.php | 4 + modules/import/edit.php | 2 +- src/Models/Upload.php | 236 +++++++++--------- src/Uploads.php | 36 +-- view.php | 44 +++- 15 files changed, 575 insertions(+), 164 deletions(-) create mode 100644 modules/adattatori_archiviazione/actions.php create mode 100644 modules/adattatori_archiviazione/add.php create mode 100644 modules/adattatori_archiviazione/edit.php create mode 100644 modules/adattatori_archiviazione/init.php create mode 100644 modules/adattatori_archiviazione/src/Adapters/FTPAdapter.php create mode 100644 modules/adattatori_archiviazione/src/Adapters/LocalAdapter.php create mode 100644 modules/adattatori_archiviazione/src/FileAdapter.php create mode 100644 modules/adattatori_archiviazione/src/OSMFilesystem.php diff --git a/actions.php b/actions.php index c7dbfab70..3acc1c477 100755 --- a/actions.php +++ b/actions.php @@ -46,13 +46,6 @@ if (filter('op') == 'aggiungi-allegato' || filter('op') == 'rimuovi-allegato') { ])); } - // Controllo sui permessi di scrittura per il file system - elseif (!directory($upload_dir)) { - flash()->error(tr('Non hai i permessi di scrittura nella cartella _DIR_!', [ - '_DIR_' => '"files"', - ])); - } - // Gestione delle operazioni else { // UPLOAD PER CKEDITOR @@ -145,6 +138,7 @@ if (filter('op') == 'aggiungi-allegato' || filter('op') == 'rimuovi-allegato') { // DELETE elseif (filter('op') == 'rimuovi-allegato' && filter('filename') !== null) { + $name = Uploads::delete(filter('filename'), [ 'id_module' => $id_module, 'id_plugin' => $id_plugin, @@ -168,7 +162,17 @@ if (filter('op') == 'aggiungi-allegato' || filter('op') == 'rimuovi-allegato') { elseif (filter('op') == 'download-allegato') { $rs = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module='.prepare($id_module).' AND id='.prepare(filter('id')).' AND filename='.prepare(filter('filename'))); - download($upload_dir.'/'.$rs[0]['filename'], $rs[0]['original']); + //download($upload_dir.'/'.$rs[0]['filename'], $rs[0]['original']); + $file = Models\Upload::find($rs[0]['id']); + + if (!empty($file)) { + $content = $file->get_contents(); + + header('Content-Type: application/octet-stream'); + header('Content-Transfer-Encoding: Binary'); + header('Content-disposition: attachment; filename="'.basename($file->original_name).'"'); + echo $content; + } } elseif (filter('op') == 'visualizza-modifica-allegato') { include_once base_dir().'/include/modifica_allegato.php'; } diff --git a/composer.json b/composer.json index 4cd961e95..3e93f74c6 100755 --- a/composer.json +++ b/composer.json @@ -43,6 +43,8 @@ "league/csv": "^9.7.0", "league/oauth2-client": "^2.6", "league/oauth2-google": "^4.0", + "league/flysystem": "^3.0", + "league/flysystem-ftp": "^3.0", "maximebf/debugbar": "^1.15", "monolog/monolog": "^1.22", "mpdf/mpdf": "^v8.0.10", @@ -110,6 +112,7 @@ "Modules\\Impostazioni\\": ["modules/impostazioni/custom/src/", "modules/impostazioni/src/"], "Modules\\Partitario\\": ["modules/partitario/custom/src/", "modules/partitario/src/"], "Modules\\StatoEmail\\": ["modules/stato_email/custom/src/", "modules/stato_email/src/"], + "Modules\\FileAdapters\\": ["modules/adattatori_archiviazione/custom/src/", "modules/adattatori_archiviazione/src/"], "Plugins\\ExportFE\\": ["plugins/exportFE/custom/src/", "plugins/exportFE/src/"], "Plugins\\ImportFE\\": ["plugins/importFE/custom/src/", "plugins/importFE/src/"], "Plugins\\ReceiptFE\\": ["plugins/receiptFE/custom/src/", "plugins/receiptFE/src/"], diff --git a/modules/adattatori_archiviazione/actions.php b/modules/adattatori_archiviazione/actions.php new file mode 100644 index 000000000..eaf388a72 --- /dev/null +++ b/modules/adattatori_archiviazione/actions.php @@ -0,0 +1,58 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +use Modules\FileAdapters\FileAdapter; + +switch (filter('op')) { + case 'add': + + $adapter = new FileAdapter(); + + $adapter->name = post('name'); + $adapter->class = "\\Modules\\FileAdapters\\Adapters\\".post('class'); + + $adapter->save(); + + $id_record = $adapter->id; + + flash()->info(tr('Nuoovo adattatore aggiunto!')); + + break; + + case 'update': + + $adapter->name = post('name'); + $adapter->class = "\\Modules\\FileAdapters\\Adapters\\".post('class'); + $adapter->options = post('options'); + $adapter->is_default = post('is_default'); + + $adapter->save(); + + flash()->info(tr('Adattatore modificato correttamente!')); + + break; + + case 'delete': + + $adapter->delete(); + + break; +} \ No newline at end of file diff --git a/modules/adattatori_archiviazione/add.php b/modules/adattatori_archiviazione/add.php new file mode 100644 index 000000000..dc4976466 --- /dev/null +++ b/modules/adattatori_archiviazione/add.php @@ -0,0 +1,43 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +?>
+ + + + +
+
+ {[ "type": "text", "label": "", "name": "name", "required": 1 ]} +
+ +
+ {[ "type": "select", "label": "", "name": "class", "values": "list=\"LocalAdapter\":\"\",\"FTPAdapter\":\"\"", "required": 1 ]} +
+
+ + +
+
+ +
+
+
\ No newline at end of file diff --git a/modules/adattatori_archiviazione/edit.php b/modules/adattatori_archiviazione/edit.php new file mode 100644 index 000000000..11ec71821 --- /dev/null +++ b/modules/adattatori_archiviazione/edit.php @@ -0,0 +1,64 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +?>
+ + + + +
+
+ {[ "type": "text", "label": "", "name": "name", "value": "$name$", "required": 1 ]} +
+ +
+ {[ "type": "select", "label": "", "name": "class", "value": "", "values": "list=\"LocalAdapter\":\"Archiviazione locale\",\"FTPAdapter\":\"Archiviazione FTP\"", "required": 1 ]} +
+ +
+ {[ "type": "checkbox", "label": "", "name": "is_default", "value": "$is_default$" ]} +
+
+ +
+
+ {[ "type": "textarea", "label": "", "name": "options", "value": "$options$", "required": 0, "help": "Specifica le opzioni per il tipo di archiviazione in formato JSON" ]} +
+
+ + + is_default && $adapter->can_delete) { + echo ' + + + '; + }else{ + echo ' +
+
+
L\'adattatore non può essere eliminato.
+
+
'; + } + ?> + +
\ No newline at end of file diff --git a/modules/adattatori_archiviazione/init.php b/modules/adattatori_archiviazione/init.php new file mode 100644 index 000000000..b2a8e0f93 --- /dev/null +++ b/modules/adattatori_archiviazione/init.php @@ -0,0 +1,28 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +use Modules\FileAdapters\FileAdapter; + +if (isset($id_record)) { + $adapter = FileAdapter::find($id_record); + + $record = $dbo->fetchOne('SELECT * FROM `zz_storage_adapters` WHERE `id`='.prepare($id_record)); +} \ No newline at end of file diff --git a/modules/adattatori_archiviazione/src/Adapters/FTPAdapter.php b/modules/adattatori_archiviazione/src/Adapters/FTPAdapter.php new file mode 100644 index 000000000..47eaee6c4 --- /dev/null +++ b/modules/adattatori_archiviazione/src/Adapters/FTPAdapter.php @@ -0,0 +1,34 @@ +. + */ + +namespace Modules\FileAdapters\Adapters; + +use League\Flysystem\Ftp\FTPAdapter as OriginalAdapter; +use League\Flysystem\Ftp\FtpConnectionOptions; + +class FTPAdapter extends OriginalAdapter { + + public function __construct( $options ){ + + $options = json_decode($options, 1); + + parent::__construct(FtpConnectionOptions::fromArray($options)); + } + +} diff --git a/modules/adattatori_archiviazione/src/Adapters/LocalAdapter.php b/modules/adattatori_archiviazione/src/Adapters/LocalAdapter.php new file mode 100644 index 000000000..d46733002 --- /dev/null +++ b/modules/adattatori_archiviazione/src/Adapters/LocalAdapter.php @@ -0,0 +1,33 @@ +. + */ + +namespace Modules\FileAdapters\Adapters; + +use League\Flysystem\Local\LocalFilesystemAdapter as OriginalAdapter; + +class LocalAdapter extends OriginalAdapter { + + public function __construct( $options ){ + + $options = json_decode($options); + + parent::__construct(base_dir()."/".$options->directory); + } + +} diff --git a/modules/adattatori_archiviazione/src/FileAdapter.php b/modules/adattatori_archiviazione/src/FileAdapter.php new file mode 100644 index 000000000..575727dcc --- /dev/null +++ b/modules/adattatori_archiviazione/src/FileAdapter.php @@ -0,0 +1,61 @@ +. + */ + +namespace Modules\FileAdapters; + +use Common\SimpleModelTrait; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\SoftDeletes; +use Traits\LocalPoolTrait; + +class FileAdapter extends Model +{ + use SimpleModelTrait; + use LocalPoolTrait; + use SoftDeletes; + + protected $table = 'zz_storage_adapters'; + + public function testConnection() + { + return true; + } + + public function setIsDefaultAttribute($valore){ + + self::getAll()->where('id', '!=', $this->id)->each(function($item){ + $item->attributes['is_default'] = false; + $item->save(); + }); + + $this->attributes['is_default'] = $valore; + } + + public static function getDefaultConnector(){ + + return self::where('is_default', 1)->first(); + } + + public static function getLocalConnector(){ + + return self::where('is_local', 1)->first(); + } + + +} \ No newline at end of file diff --git a/modules/adattatori_archiviazione/src/OSMFilesystem.php b/modules/adattatori_archiviazione/src/OSMFilesystem.php new file mode 100644 index 000000000..e73042c14 --- /dev/null +++ b/modules/adattatori_archiviazione/src/OSMFilesystem.php @@ -0,0 +1,73 @@ +. + */ + +namespace Modules\FileAdapters; + +use League\Flysystem\Filesystem; + +class OSMFilesystem extends Filesystem +{ + + /** @var array Elenco delle tipologie di file pericolose */ + protected static $not_allowed_types = [ + 'php' => 'application/php', + 'php5' => 'application/php', + 'phtml' => 'application/php', + 'html' => 'text/html', + 'htm' => 'text/html', + ]; + + public function upload($directory, $filename, $contents){ + + //Verifico se l'esensione non è consentita + $extension = pathinfo($filename, PATHINFO_EXTENSION); + $extension = strtolower($extension); + + // Controllo sulle estensioni permesse + $allowed = self::isSupportedType($extension); + if (!$allowed) { + flash()->error(tr('Estensione non supportata!')); + return false; + } + + if(!$this->directoryExists($directory)){ + try{ + $this->createDirectory($directory); + }catch(\Exception $e){ + flash()->error(tr('Impossibile creare la cartella controllare i permessi!')); + return false; + } + } + + do { + $filename = random_string().'.'.$extension; + } while ($this->fileExists($directory.'/'.$filename)); + + + $this->write($directory."/".$filename, $contents); + return ["filename" => $filename, "extension" => $extension]; + } + + protected static function isSupportedType($extension) + { + return !in_array(strtolower($extension), array_keys(self::$not_allowed_types)); + } + + +} \ No newline at end of file diff --git a/modules/import/actions.php b/modules/import/actions.php index 52425dfc3..0242a5e45 100755 --- a/modules/import/actions.php +++ b/modules/import/actions.php @@ -19,6 +19,7 @@ use Modules\Importazione\Import; use Models\Module; +use Modules\FileAdapters\FileAdapter; include_once __DIR__.'/../../core.php'; @@ -28,13 +29,16 @@ switch (filter('op')) { case 'add': $id_import = filter('id_import'); $import = Import::find($id_import); + $id_adapter = FileAdapter::getLocalConnector()->id; $id_record = $import->id; Uploads::upload($_FILES['file'], [ 'id_module' => $id_module, 'id_record' => $id_record, + 'id_adapter' => $id_adapter, ]); + break; case 'example': diff --git a/modules/import/edit.php b/modules/import/edit.php index 2732d5de5..3e1f347f3 100755 --- a/modules/import/edit.php +++ b/modules/import/edit.php @@ -33,7 +33,7 @@ if (empty($id_record)) { $import_selezionato = $import->class; // Inizializzazione del lettore CSV - $csv = new $import_selezionato($record->filepath); + $csv = new $import_selezionato($record->local_filepath); $fields = $csv->getAvailableFields(); // Generazione della base per i campi da selezionare diff --git a/src/Models/Upload.php b/src/Models/Upload.php index d7f74a16f..d8620f034 100755 --- a/src/Models/Upload.php +++ b/src/Models/Upload.php @@ -22,21 +22,13 @@ namespace Models; use Common\SimpleModelTrait; use Illuminate\Database\Eloquent\Model; use Intervention\Image\ImageManagerStatic; -use Util\FileSystem; +use Modules\FileAdapters\FileAdapter; +use Modules\FileAdapters\OSMFilesystem; class Upload extends Model { use SimpleModelTrait; - /** @var array Elenco delle tipologie di file pericolose */ - protected static $not_allowed_types = [ - 'php' => 'application/php', - 'php5' => 'application/php', - 'phtml' => 'application/php', - 'html' => 'text/html', - 'htm' => 'text/html', - ]; - /** @var array Elenco delle estensioni file per mime type */ protected static $extension_association = [ 'image/gif' => 'gif', @@ -99,31 +91,49 @@ class Upload extends Model $model->id_plugin = !empty($data['id_plugin']) ? $data['id_plugin'] : null; $model->id_record = !empty($data['id_record']) ? $data['id_record'] : null; - // Definizione del nome fisico del file - $directory = base_dir().'/'.$model->directory; - $filename = self::getNextName($original_name, $directory); - if (empty($filename)) { - throw new \UnexpectedValueException("Estensione dell'allegato non supportata"); + //Caricamento file con interfaccia di upload + + //Verifico qual'è il metodo predefinito al momento + if(!empty($data['id_adapter'])){ + $adapter_config = FileAdapter::find($data['id_adapter']); + }else{ + $adapter_config = FileAdapter::getDefaultConnector(); } - $model->filename = $filename; + $class = $adapter_config->class; - // Creazione del file fisico - directory($directory); - $file = slashes($directory.DIRECTORY_SEPARATOR.$filename); - if ( - (is_array($source) && is_uploaded_file($source['tmp_name']) && !move_uploaded_file($source['tmp_name'], $file)) - || (is_string($source) && is_file($source) && !copy($source, $file)) - || (is_string($source) && !is_file($source) && file_put_contents($file, $source) === false) - ) { - throw new \UnexpectedValueException("Errore durante il salvataggio dell'allegato"); + //Costruisco l'oggetto che mi permetterà di effettuare il caricamento + $adapter = new $class($adapter_config->options); + $filesystem = new OSMFilesystem($adapter); + + //Su source arriva direttamente il contenuto o il formato file + if (is_array($source)) { + //Caricamento con l'interfaccia di upload + try{ + $file = $filesystem->upload($model->directory, $original_name, file_get_contents($source['tmp_name'])); + }catch(\Exception $e){ + flash()->error(tr('Impossibile creare il file!')); + return false; + } + + // Aggiornamento dimensione fisica e responsabile del caricamento + $model->size = $source['size']; + }else{ + //Caricamento con l'interfaccia di upload + try{ + $file = $filesystem->upload($model->directory, $original_name, $source); + }catch(\Exception $e){ + flash()->error(tr('Impossibile creare il file!')); + return false; + } } - // Aggiornamento dimensione fisica e responsabile del caricamento - $model->size = FileSystem::fileSize($file); + $model->id_adapter = $adapter_config->id; + $model->filename = $file['filename']; + $model->user()->associate(auth()->getUser()); // Rimozione estensione dal nome visibile - $extension = $model->extension; + $extension = $file['extension']; if (string_ends_with($model->name, $extension)) { $length = strlen($extension) + 1; $model->name = substr($model->name, 0, -$length); @@ -134,29 +144,6 @@ class Upload extends Model return $model; } - /** - * @return array - */ - public function getInfoAttribute() - { - if (!isset($this->file_info)) { - $filepath = $this->filepath; - $infos = self::getInfo($filepath); - - $this->file_info = $infos; - } - - return $this->file_info; - } - - /** - * @return string|null - */ - public function getExtensionAttribute() - { - return strtolower($this->info['extension']); - } - /** * @return string */ @@ -164,23 +151,7 @@ class Upload extends Model { $parent = $this->plugin ?: $this->module; - return $parent->upload_directory; - } - - /** - * @return string - */ - public function getFilepathAttribute() - { - return $this->directory.'/'.$this->filename; - } - - /** - * @return string - */ - public function getFileurlAttribute() - { - return str_replace('\\', '/', $this->filepath); + return strtolower($parent->name); } /** @@ -196,16 +167,6 @@ class Upload extends Model $this->attributes['original'] = $value; } - /** - * Restituisce i contenuti del file. - * - * @return false|string - */ - public function getContent() - { - return file_get_contents($this->filepath); - } - /** * @return bool */ @@ -254,17 +215,14 @@ class Upload extends Model public function delete() { - $info = $this->info; - $directory = base_dir().'/'.$this->directory; + $adapter_config = FileAdapter::find($this->id_adapter); + $class = $adapter_config->class; - $files = [ - $directory.'/'.$info['basename'], - $directory.'/'.$info['filename'].'_thumb600.'.$info['extension'], - $directory.'/'.$info['filename'].'_thumb100.'.$info['extension'], - $directory.'/'.$info['filename'].'_thumb250.'.$info['extension'], - ]; + //Costruisco l'oggetto che mi permetterà di effettuare il caricamento + $adapter = new $class($adapter_config->options); + $filesystem = new OSMFilesystem($adapter); - delete($files); + $filesystem->delete($this->directory."/".$this->filename); return parent::delete(); } @@ -280,16 +238,24 @@ class Upload extends Model public function copia($data) { - $result = self::build(base_dir().'/'.$this->filepath, $data, $this->name, $this->category); + $data['original_name'] = $this->original_name; + + $adapter_config = FileAdapter::find($this->id_adapter); + $class = $adapter_config->class; + + //Costruisco l'oggetto che mi permetterà di effettuare il caricamento + $adapter = new $class($adapter_config->options); + $filesystem = new OSMFilesystem($adapter); + + $source = $this->get_contents(); + + $file = $filesystem->read($this->directory."/".$this->filename); + + $result = self::build($file, $data, $this->name, $this->category); return $result; } - public static function getInfo($file) - { - return pathinfo($file); - } - /* Relazioni Eloquent */ public function module() @@ -307,39 +273,33 @@ class Upload extends Model return $this->belongsTo(User::class, 'created_by'); } - /** - * Controlla se l'estensione è supportata dal sistema di upload. - * - * @param string $extension - * - * @return bool - */ - protected static function isSupportedType($extension) - { - return !in_array(strtolower($extension), array_keys(self::$not_allowed_types)); + public function get_contents(){ + $adapter_config = FileAdapter::find($this->id_adapter); + $class = $adapter_config->class; + + //Costruisco l'oggetto che mi permetterà di effettuare il caricamento + $adapter = new $class($adapter_config->options); + $filesystem = new OSMFilesystem($adapter); + + return $filesystem->read($this->directory."/".$this->filename); } /** - * Genera casualmente il nome fisico per il file. - * * @return string */ - protected static function getNextName($file, $directory) + public function getLocalFilepathAttribute() { - $extension = self::getInfo($file)['extension']; - $extension = strtolower($extension); + $parent = $this->plugin ?: $this->module; - // Controllo sulle estensioni permesse - $allowed = self::isSupportedType($extension); - if (!$allowed) { - return false; - } + return $parent->upload_directory.'/'.$this->filename; + } - do { - $filename = random_string().'.'.$extension; - } while (file_exists($directory.'/'.$filename)); - - return $filename; + /** + * @return string + */ + public function getLocalFileurlAttribute() + { + return str_replace('\\', '/', $this->local_filepath); } /** @@ -376,4 +336,44 @@ class Upload extends Model }); $img->save(slashes($directory.'/'.$info['filename'].'_thumb100.'.$info['extension'])); } + + /** + * @return array + */ + public function getInfoAttribute() + { + if (!isset($this->file_info)) { + $filepath = $this->local_filepath; + $infos = self::getInfo($local_filepath); + + $this->file_info = $infos; + } + + return $this->file_info; + } + + /** + * @return string|null + */ + public function getExtensionAttribute() + { + $extension = pathinfo($this->filename, PATHINFO_EXTENSION); + $extension = strtolower($extension); + return $extension; + } + + /** + * Restituisce i contenuti del file locale. + * + * @return false|string + */ + public function getContent() + { + return file_get_contents($this->local_filepath); + } + + public static function getInfo($file) + { + return pathinfo($file); + } } diff --git a/src/Uploads.php b/src/Uploads.php index adf5aec23..daf10fc41 100755 --- a/src/Uploads.php +++ b/src/Uploads.php @@ -100,34 +100,18 @@ class Uploads 'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null, 'id_record' => $data['id_record'], ]); - $name = $file['name']; - - $fileinfo = self::fileInfo($filename); - $directory = base_dir().'/'.self::getDirectory($data['id_module'], $data['id_plugin']); - - $files = [ - $directory.'/'.$fileinfo['basename'], - $directory.'/'.$fileinfo['filename'].'_thumb600.'.$fileinfo['extension'], - $directory.'/'.$fileinfo['filename'].'_thumb100.'.$fileinfo['extension'], - $directory.'/'.$fileinfo['filename'].'_thumb250.'.$fileinfo['extension'], - ]; - - if (delete($files)) { - $database->delete('zz_files', [ - 'filename' => $fileinfo['basename'], - 'id_module' => !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null, - 'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null, - 'id_record' => $data['id_record'], - ]); - - if ((new Module())->getByName('Stampe')->id_record == $data['id_module']) { - $database->delete('zz_files_print', [ - 'id_file' => $file['id'], - ]); - } - + + if(!empty($file)){ + $name = $file['name']; + + $upload = Upload::find($file['id']); + $upload->delete(); + return $name; + }else{ + return null; } + } return null; diff --git a/view.php b/view.php index b8b6b933f..3e1dff6f7 100755 --- a/view.php +++ b/view.php @@ -27,20 +27,38 @@ if (empty($file)) { return; } -$link = base_path().'/'.$file->filepath; +$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).'"'); - readfile(base_dir().'/'.$file->filepath); - // download(base_dir().'/'.$file->filepath, 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()) { - $content = file_get_contents(base_dir().'/'.$file->filepath); // Individuazione stylesheet $default_stylesheet = 'asso-invoice'; @@ -55,7 +73,7 @@ if ($file->isFatturaElettronica()) { // XML $xml = new DOMDocument(); - $xml->loadXML($content); + $xml->loadXML($file_content); // XSL $xsl = new DOMDocument(); @@ -89,15 +107,19 @@ if ($file->isFatturaElettronica()) { '; if ($file->isImage()) { - echo ' - '; - } elseif ($file->isPDF()) { - $preview = Prints::getPDFLink($file->filepath); echo ' - '; + + } elseif ($file->isPDF()) { + + echo ' + '; + } else { echo '