🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:ClientController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use App\Models\Project; use App\Models\ProjectResource; use App\Models\ProjectMedia; use App\Models\Requirement; use App\Models\Payment; use Illuminate\Support\Facades\Storage; class ClientController extends Controller { public function dashboard() { $user = Auth::user(); $projects = Project::with(['requirements', 'tasks', 'payments']) ->where('client_id', $user->id) ->get(); if ($projects->isEmpty()) { $projects = Project::with(['requirements', 'tasks', 'payments'])->get(); } $requirements = Requirement::where('client_id', $user->id) ->orderBy('created_at', 'desc') ->get(); // Get payment summary for each project $paymentSummary = []; foreach ($projects as $project) { $confirmedPayments = $project->payments()->where('status', 'confirmed')->sum('amount'); $pendingPayments = $project->payments()->where('status', 'pending')->sum('amount'); $paymentSummary[$project->id] = [ 'total_budget' => $project->budget ?? 0, 'confirmed' => $confirmedPayments, 'pending' => $pendingPayments, 'balance' => ($project->budget ?? 0) - $confirmedPayments, ]; } return view('client.dashboard', compact('projects', 'requirements', 'paymentSummary')); } public function storeRequirement(Request $request) { $request->validate([ 'project_id' => 'required|exists:projects,id', 'title' => 'required|string|max:255', 'description' => 'nullable|string', 'file' => 'nullable|file|max:10240', // 10MB max ]); $project = Project::findOrFail($request->project_id); $filePath = null; if ($request->hasFile('file')) { $filePath = $request->file('file')->store('requirements', 'public'); } $requirement = Requirement::create([ 'project_id' => $project->id, 'client_id' => Auth::id(), 'title' => $request->title, 'description' => $request->description, 'file_path' => $filePath, 'status' => 'pending', ]); // Notify Tech Lead if ($project->tech_lead_id) { $techLead = \App\Models\User::find($project->tech_lead_id); if ($techLead) { \Illuminate\Support\Facades\Mail::to($techLead->email)->queue( new \App\Mail\SystemNotification( 'New Requirement Submitted: ' . $requirement->title, 'A new requirement has been submitted by ' . Auth::user()->name . ' for project "' . $project->name . '". Please review and approve.', 'Review Requirement', route('techlead.dashboard') ) ); } } return redirect()->back()->with('success', 'Requirement submitted successfully. It is now pending review.'); } // ────────────────────────────────────────────── // Project Media Uploads (record / upload) // ────────────────────────────────────────────── public function media(Project $project) { if ($project->client_id !== auth()->id()) { abort(403); } $project->load('media'); $totalUsed = $project->media->sum('file_size'); $limit = 5 * 1024 * 1024 * 1024; // 5GB return view('client.media', compact('project', 'totalUsed', 'limit')); } public function storeMedia(Request $request, Project $project) { if ($project->client_id !== auth()->id()) abort(403); $request->validate([ 'file' => 'required|file|max:5120000', // 5GB max 'media_type' => 'nullable|in:voice,camera,back_camera,video_upload,document,image', ]); $file = $request->file('file'); $mime = $file->getClientMimeType(); // Auto-detect media_type if not provided $mediaType = $request->media_type; if (!$mediaType) { if (str_starts_with($mime, 'image/')) { $mediaType = 'image'; } elseif (in_array($mime, ['application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'])) { $mediaType = 'document'; } elseif (str_starts_with($mime, 'video/')) { $mediaType = 'video_upload'; } elseif (str_starts_with($mime, 'audio/')) { $mediaType = 'voice'; } else { $mediaType = 'document'; } } // Check total project media size limit $totalUsed = ProjectMedia::where('project_id', $project->id)->sum('file_size'); $limit = 5 * 1024 * 1024 * 1024; if (($totalUsed + $file->getSize()) > $limit) { return redirect()->back()->with('error', 'Total media size would exceed the 5GB limit for this project.'); } $path = $file->store('project_media/' . $project->id, 'public'); ProjectMedia::create([ 'project_id' => $project->id, 'client_id' => auth()->id(), 'media_type' => $mediaType, 'file_path' => $path, 'file_name' => $file->getClientOriginalName(), 'file_size' => $file->getSize(), 'mime_type' => $mime, 'duration' => $request->duration, ]); return redirect()->back()->with('success', 'Media uploaded successfully.'); } public function storeRecording(Request $request, Project $project) { if ($project->client_id !== auth()->id()) abort(403); $request->validate([ 'blob' => 'required|file|max:5120000', 'media_type' => 'required|in:voice,camera,back_camera', ]); $blob = $request->file('blob'); // Check total project media size limit $totalUsed = ProjectMedia::where('project_id', $project->id)->sum('file_size'); $limit = 5 * 1024 * 1024 * 1024; if (($totalUsed + $blob->getSize()) > $limit) { return response()->json(['error' => 'Total media size would exceed the 5GB limit.'], 413); } $ext = $request->media_type === 'voice' ? 'webm' : 'webm'; $name = $request->media_type . '_' . time() . '.' . $ext; $path = $blob->storeAs('project_media/' . $project->id, $name, 'public'); ProjectMedia::create([ 'project_id' => $project->id, 'client_id' => auth()->id(), 'media_type' => $request->media_type, 'file_path' => $path, 'file_name' => $name, 'file_size' => $blob->getSize(), 'mime_type' => $blob->getClientMimeType(), 'duration' => $request->duration, ]); return response()->json(['success' => true, 'message' => 'Recording saved successfully.']); } public function deleteMedia(ProjectMedia $media) { $project = $media->project; if ($project->client_id !== auth()->id()) abort(403); Storage::disk('public')->delete($media->file_path); $media->delete(); return redirect()->back()->with('success', 'Media deleted successfully.'); } // ────────────────────────────────────────────── // Download Project Resources (completed only) // ────────────────────────────────────────────── public function resources(Project $project) { if ($project->client_id !== auth()->id()) { abort(403); } if ($project->status !== 'completed') { return redirect()->back()->with('error', 'Resources are only available after project completion.'); } $resources = $project->resources()->where('is_downloadable', true)->get(); return view('client.resources', compact('project', 'resources')); } }
Save Changes
Cancel
Create New File
Create New Folder