From 8fd28e89325b49031b02a429eb1fa325e4085e41 Mon Sep 17 00:00:00 2001 From: valentina Date: Mon, 26 Aug 2024 12:30:39 +0200 Subject: [PATCH] Fix upload immagine utente --- modules/utenti/components/photo.php | 4 +++- src/HTMLBuilder/Manager/FileManager.php | 1 + src/Models/Upload.php | 3 ++- src/Models/User.php | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/utenti/components/photo.php b/modules/utenti/components/photo.php index e63a606f4..211e33284 100755 --- a/modules/utenti/components/photo.php +++ b/modules/utenti/components/photo.php @@ -18,8 +18,10 @@ */ include_once __DIR__.'/../../core.php'; +use Models\Upload; + +$user_photo = $rootdir.'/files/utenti/'.Upload::find($user->image_file_id)->filename; -$user_photo = $user->photo; if ($user_photo) { echo '
'.$user['username'].'
'; diff --git a/src/HTMLBuilder/Manager/FileManager.php b/src/HTMLBuilder/Manager/FileManager.php index 2cef20b00..a18b6a1ef 100755 --- a/src/HTMLBuilder/Manager/FileManager.php +++ b/src/HTMLBuilder/Manager/FileManager.php @@ -22,6 +22,7 @@ namespace HTMLBuilder\Manager; use Models\Upload; use Util\FileSystem; + /** * Gestione allegati. * diff --git a/src/Models/Upload.php b/src/Models/Upload.php index 4fbc80c7c..344cecd3b 100755 --- a/src/Models/Upload.php +++ b/src/Models/Upload.php @@ -74,8 +74,9 @@ class Upload extends Model $model = new static(); // Informazioni di base - $original_name = $source['name'] ?? basename($source); $name = $data['name'] ?? $name; + $name ??= basename($source); + $original_name = $source['name'] ?? $name; $category = $data['category'] ?? $category; // Nome e categoria dell'allegato diff --git a/src/Models/User.php b/src/Models/User.php index 4c9200e20..9cfad15b5 100755 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -149,7 +149,7 @@ class User extends Model $image = Upload::find($this->image_file_id); - return base_path().'/'.$image->filepath; + return base_path().'/files/'.$image->module->directory.'/'.$image->filename; } public function setPhotoAttribute($value) @@ -179,7 +179,7 @@ class User extends Model $img->save(slashes($file)); // Aggiunta nuova foto - $upload = Upload::build($file, $data); + $upload = Upload::build(file_get_contents($file), $data, basename($value['name'])); // Rimozione foto precedenti delete($file);