283 lines
9.8 KiB
PHP
283 lines
9.8 KiB
PHP
<?php
|
||
// Fix: Finales Bild-Upload-System
|
||
echo "📸 Fix: Finales Bild-Upload-System\n";
|
||
echo "==================================\n\n";
|
||
|
||
// 1. Controller mit vereinfachtem Upload erstellen (ohne Intervention Image)
|
||
echo "1. 🔧 Controller mit vereinfachtem Upload erstellen...\n";
|
||
|
||
$controllerContent = '<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
use App\Models\NailPolish;
|
||
use App\Models\User;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Facades\Auth;
|
||
use Illuminate\Support\Facades\Storage;
|
||
|
||
class UserNailPolishController extends Controller
|
||
{
|
||
/**
|
||
* Zeigt die Sammlung des aktuellen Benutzers an
|
||
*/
|
||
public function index(Request $request)
|
||
{
|
||
$user = Auth::user();
|
||
$search = $request->get("search");
|
||
|
||
$query = $user->nailPolishes();
|
||
|
||
if ($search) {
|
||
$query->where(function($q) use ($search) {
|
||
$q->where("name", "like", "%{$search}%")
|
||
->orWhere("number", "like", "%{$search}%");
|
||
});
|
||
}
|
||
|
||
$nailPolishes = $query->orderBy("name")->paginate(12);
|
||
|
||
return view("user-nail-polishes.index", compact("nailPolishes", "search"));
|
||
}
|
||
|
||
/**
|
||
* Zeigt alle verfügbaren Lacke an, die der User noch nicht hat
|
||
*/
|
||
public function available(Request $request)
|
||
{
|
||
$user = Auth::user();
|
||
$search = $request->get("search");
|
||
|
||
$query = NailPolish::whereNotIn("id", $user->nailPolishes()->pluck("nail_polishes.id"));
|
||
|
||
if ($search) {
|
||
$query->search($search);
|
||
}
|
||
|
||
$nailPolishes = $query->orderBy("name")->paginate(12);
|
||
|
||
return view("user-nail-polishes.available", compact("nailPolishes", "search"));
|
||
}
|
||
|
||
/**
|
||
* Fügt einen Lack zur Sammlung des Users hinzu
|
||
*/
|
||
public function add(NailPolish $nailPolish)
|
||
{
|
||
$user = Auth::user();
|
||
|
||
// Prüfe, ob der Lack bereits in der Sammlung ist
|
||
if ($user->nailPolishes()->where("nail_polish_id", $nailPolish->id)->exists()) {
|
||
return back()->with("warning", "Dieser Lack ist bereits in Ihrer Sammlung!");
|
||
}
|
||
|
||
$user->nailPolishes()->attach($nailPolish->id);
|
||
|
||
return back()->with("success", "Lack \"{$nailPolish->name}\" wurde zu Ihrer Sammlung hinzugefügt!");
|
||
}
|
||
|
||
/**
|
||
* Entfernt einen Lack aus der Sammlung des Users
|
||
*/
|
||
public function remove(NailPolish $nailPolish)
|
||
{
|
||
try {
|
||
$user = Auth::user();
|
||
|
||
// Prüfe, ob der Lack in der Sammlung ist
|
||
if (!$user->nailPolishes()->where("nail_polish_id", $nailPolish->id)->exists()) {
|
||
return back()->with("warning", "Dieser Lack ist nicht in Ihrer Sammlung!");
|
||
}
|
||
|
||
$user->nailPolishes()->detach($nailPolish->id);
|
||
|
||
return back()->with("success", "Lack \"{$nailPolish->name}\" wurde aus Ihrer Sammlung entfernt!");
|
||
|
||
} catch (\Exception $e) {
|
||
\Log::error("Fehler beim Entfernen des Lackes: " . $e->getMessage());
|
||
return back()->with("error", "Fehler beim Entfernen des Lackes. Bitte versuchen Sie es erneut.");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Zeigt das Formular zum Erstellen eines neuen Lackes
|
||
*/
|
||
public function create()
|
||
{
|
||
return view("user-nail-polishes.create");
|
||
}
|
||
|
||
/**
|
||
* Speichert einen neuen Lack (wird automatisch zum Hauptkatalog hinzugefügt)
|
||
*/
|
||
public function store(Request $request)
|
||
{
|
||
$request->validate([
|
||
"name" => "required|string|max:255",
|
||
"number" => "required|string|max:50",
|
||
"image" => "nullable|image|max:10240", // Max 10MB
|
||
], [
|
||
"name.required" => "Der Name des Lackes ist erforderlich.",
|
||
"number.required" => "Die Nummer des Lackes ist erforderlich.",
|
||
"image.image" => "Die Datei muss ein Bild sein.",
|
||
"image.max" => "Das Bild darf maximal 10MB groß sein.",
|
||
]);
|
||
|
||
try {
|
||
$nailPolish = new NailPolish();
|
||
$nailPolish->name = trim($request->name);
|
||
$nailPolish->number = trim($request->number);
|
||
|
||
// Vereinfachte Bildverarbeitung ohne Intervention Image
|
||
if ($request->hasFile("image") && $request->file("image")->isValid()) {
|
||
$image = $request->file("image");
|
||
|
||
// Erstelle einen eindeutigen Dateinamen
|
||
$filename = "nail_polish_" . time() . "_" . uniqid() . "." . $image->getClientOriginalExtension();
|
||
$path = "nail_polishes/" . $filename;
|
||
|
||
// Speichere das Bild direkt ohne Verarbeitung
|
||
Storage::disk("public")->putFileAs("nail_polishes", $image, $filename);
|
||
$nailPolish->image_path = $path;
|
||
|
||
\Log::info("Bild erfolgreich gespeichert: " . $path);
|
||
}
|
||
|
||
$nailPolish->save();
|
||
|
||
// Füge den Lack automatisch zur Sammlung des Users hinzu
|
||
$user = Auth::user();
|
||
$user->nailPolishes()->attach($nailPolish->id);
|
||
|
||
return redirect()->route("user-nail-polishes.index")
|
||
->with("success", "Lack \"{$nailPolish->name}\" wurde erfolgreich erstellt und zu Ihrer Sammlung hinzugefügt!");
|
||
|
||
} catch (\Exception $e) {
|
||
\Log::error("Fehler beim Erstellen des Lackes: " . $e->getMessage());
|
||
return back()->with("error", "Fehler beim Erstellen des Lackes: " . $e->getMessage())
|
||
->withInput();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Zeigt die Sammlung eines bestimmten Users (für Admin)
|
||
*/
|
||
public function showUserCollection(User $user)
|
||
{
|
||
$nailPolishes = $user->nailPolishes()->orderBy("name")->paginate(12);
|
||
|
||
return view("user-nail-polishes.show-user", compact("user", "nailPolishes"));
|
||
}
|
||
}';
|
||
|
||
file_put_contents('app/Http/Controllers/UserNailPolishController.php', $controllerContent);
|
||
echo " ✅ Controller mit vereinfachtem Upload erstellt\n";
|
||
|
||
// 2. Storage-Verzeichnisse erstellen
|
||
echo "2. 📁 Storage-Verzeichnisse erstellen...\n";
|
||
$directories = [
|
||
'storage/app/public',
|
||
'storage/app/public/nail_polishes'
|
||
];
|
||
|
||
foreach ($directories as $dir) {
|
||
if (!is_dir($dir)) {
|
||
mkdir($dir, 0755, true);
|
||
echo " ✅ Verzeichnis erstellt: $dir\n";
|
||
} else {
|
||
echo " ℹ️ Verzeichnis existiert bereits: $dir\n";
|
||
}
|
||
}
|
||
|
||
// 3. Berechtigungen setzen
|
||
echo "3. 🔐 Berechtigungen setzen...\n";
|
||
system('chmod -R 755 storage/');
|
||
system('chown -R www-data:www-data storage/ 2>/dev/null || echo " ⚠️ chown fehlgeschlagen"');
|
||
echo " ✅ Berechtigungen gesetzt\n";
|
||
|
||
// 4. Storage Link erstellen
|
||
echo "4. 🔗 Storage Link erstellen...\n";
|
||
if (file_exists('public/storage')) {
|
||
if (is_dir('public/storage')) {
|
||
system('rm -rf public/storage');
|
||
}
|
||
}
|
||
system('ln -sf ../storage/app/public public/storage');
|
||
echo " ✅ Storage Link erstellt\n";
|
||
|
||
// 5. Laravel Cache leeren
|
||
echo "5. 🧹 Laravel Cache leeren...\n";
|
||
system('php artisan cache:clear 2>/dev/null || echo " ⚠️ cache:clear übersprungen"');
|
||
system('php artisan config:clear 2>/dev/null || echo " ⚠️ config:clear übersprungen"');
|
||
system('php artisan view:clear 2>/dev/null || echo " ⚠️ view:clear übersprungen"');
|
||
system('php artisan route:clear 2>/dev/null || echo " ⚠️ route:clear übersprungen"');
|
||
echo " ✅ Cache geleert\n";
|
||
|
||
// 6. Test-Bild erstellen
|
||
echo "6. 🖼️ Test-Bild erstellen...\n";
|
||
$testImagePath = 'storage/app/public/nail_polishes/test.jpg';
|
||
if (extension_loaded('gd')) {
|
||
$image = imagecreate(100, 100);
|
||
$bgColor = imagecolorallocate($image, 255, 255, 255);
|
||
$textColor = imagecolorallocate($image, 0, 0, 0);
|
||
imagestring($image, 5, 10, 40, 'TEST', $textColor);
|
||
|
||
if (imagejpeg($image, $testImagePath, 80)) {
|
||
echo " ✅ Test-Bild erstellt: $testImagePath\n";
|
||
} else {
|
||
echo " ❌ Test-Bild erstellen fehlgeschlagen\n";
|
||
}
|
||
|
||
imagedestroy($image);
|
||
} else {
|
||
echo " ❌ GD Extension nicht verfügbar\n";
|
||
}
|
||
|
||
// 7. Upload-Limits in .htaccess prüfen
|
||
echo "7. 📏 Upload-Limits prüfen...\n";
|
||
$htaccessPath = 'public/.htaccess';
|
||
if (file_exists($htaccessPath)) {
|
||
$htaccessContent = file_get_contents($htaccessPath);
|
||
|
||
$requiredSettings = [
|
||
'upload_max_filesize 10M',
|
||
'post_max_size 10M',
|
||
'max_file_uploads 20',
|
||
'memory_limit 256M'
|
||
];
|
||
|
||
$missingSettings = [];
|
||
foreach ($requiredSettings as $setting) {
|
||
if (strpos($htaccessContent, $setting) === false) {
|
||
$missingSettings[] = $setting;
|
||
}
|
||
}
|
||
|
||
if (empty($missingSettings)) {
|
||
echo " ✅ Alle Upload-Limits in .htaccess vorhanden\n";
|
||
} else {
|
||
echo " ⚠️ Fehlende Upload-Limits: " . implode(', ', $missingSettings) . "\n";
|
||
|
||
// Füge fehlende Settings hinzu
|
||
$uploadSettings = "\n# Upload-Limits für Bild-Upload\n";
|
||
foreach ($missingSettings as $setting) {
|
||
$uploadSettings .= "php_value " . $setting . "\n";
|
||
}
|
||
|
||
$htaccessContent .= $uploadSettings;
|
||
file_put_contents($htaccessPath, $htaccessContent);
|
||
echo " ✅ Upload-Limits zu .htaccess hinzugefügt\n";
|
||
}
|
||
} else {
|
||
echo " ❌ .htaccess nicht gefunden\n";
|
||
}
|
||
|
||
echo "\n✅ Finales Bild-Upload-System erstellt!\n";
|
||
echo "🔗 Testen Sie jetzt: https://neonail.vogt.de.com/create-nail-polish\n";
|
||
echo "📝 Das System speichert Bilder jetzt direkt ohne Verarbeitung\n";
|
||
echo "📋 Falls Upload immer noch fehlschlägt:\n";
|
||
echo "- Prüfen Sie die Laravel-Logs: tail -f storage/logs/laravel.log\n";
|
||
echo "- Testen Sie mit einem kleinen Bild (< 1MB)\n";
|
||
echo "- Prüfen Sie Browser-Entwicklertools (F12) für Netzwerk-Fehler\n";
|
||
?>
|