generateCustomFilename($file); // /* This line of code is uploading the file to Amazon S3 and storing it in the specified // location with the specified filename. The `storeAs()` method is a Laravel method // that saves the uploaded file to a disk (in this case, the S3 disk) with a custom // filename. The first parameter specifies the path where the file should be stored, // the second parameter specifies the custom filename, and the third parameter // specifies the disk where the file should be stored (in this case, the S3 disk). The // method returns the path where the file was stored. */ // $path = $file->storeAs('path/to/your/desired/location', $fileName, 's3'); // if ($path) { // $event->file_url = $path; // } // // Do something with the uploaded file path // if ($event->save()) // return response()->json(['message' => 'File uploaded successfully']); // } catch (AwsException $e) { // // Handle any errors that occur during the upload // return response()->json(['error' => $e->getMessage()], 500); // } // require 'vendor/autoload.php'; // $s3 = new S3ClientInstance([ // 'region' => config('filesystems.disks.s3.region'), // 'version' => 'latest', // 'credentials' => [ // 'key' => config('filesystems.disks.s3.key'), // 'secret' => config('filesystems.disks.s3.secret'), // ] // ]); // $path = $s3->putObject([ // 'Bucket' => config('filesystems.disks.s3.bucket'), // 'Key' => $fileName, // 'SourceFile' => $file // ]); // $originalFileName = $file->getClientOriginalName(); $serverFileName = $this->generateCustomFilename($file); $path = Storage::disk(Helper::getMediaServerType()) ->put($serverFileName, file_get_contents($file), 'event_uploads'); if ($path) { $event->file_url = $path; } // Do something with the uploaded file path if ($event->save()) return response()->json(['message' => 'File uploaded successfully']); } /** * This PHP function generates a custom filename for a given file by appending a timestamp and file * extension. * * @param file The parameter is an instance of the UploadedFile class, which represents a file * uploaded through a form. It contains information about the file, such as its name, size, and MIME * type. * * @return a string that represents a custom filename for a given file. The filename is generated by * concatenating the current timestamp with the file extension. */ private function generateCustomFilename($file) { $timestamp = time(); /* ` = ->getClientOriginalExtension();` is retrieving the original extension of the uploaded file. This is useful for generating a custom filename for the file, as it allows the extension to be included in the filename. */ $extension = $file->getClientOriginalExtension(); $fileName = $timestamp . '.' . $extension; return $fileName; } }