Consider a Laravel controller method that handles file uploads but does not validate the file type or size. What is the likely outcome when a user uploads a very large or unsupported file?
<?php
public function upload(Request $request) {
$path = $request->file('document')->store('uploads');
return back()->with('message', 'File uploaded!');
}Think about what happens if you don't tell Laravel to check the file before saving.
Without explicit validation, Laravel will store any uploaded file regardless of size or type. This can lead to security risks or storage problems.
Choose the code snippet that stores an uploaded file with a custom name preserving the original extension.
Remember to preserve the original file extension and use the correct method to store with a custom name.
Option C uses getClientOriginalExtension() to get the original extension and storeAs to save with a custom filename.
Examine the code below. It throws an error when uploading a file. What is the cause?
<?php
public function upload(Request $request) {
$file = $request->file('document');
$path = $file->store('uploads', 'public');
return back()->with('message', 'Uploaded!');
}Check if the file input name matches the request key.
If the input name in the form is not 'document', $request->file('document') returns null. Calling store on null causes an error.
Given the code below, what will be the value of $filename if the uploaded file is named report.pdf?
<?php
$file = $request->file('upload');
$filename = $file->hashName();hashName generates a unique name with the original extension.
The hashName() method returns a unique filename using a hash and keeps the original file extension.
Among the options below, which Laravel feature best helps protect uploaded files from unauthorized access while allowing controlled retrieval?
Think about Laravel's built-in tools for file storage and secure access.
Laravel's Storage facade supports private disks and temporary signed URLs, allowing files to be stored securely and accessed only with authorized links.