0
0
Laravelframework~5 mins

Uploading files in Laravel - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the basic Laravel method to handle file uploads in a controller?
Use the store() method on the uploaded file instance, like $request->file('photo')->store('folder') to save the file in storage.
Click to reveal answer
beginner
How do you validate an uploaded file in Laravel?
Use the validate() method on the request with rules like 'file' => 'required|file|mimes:jpg,png|max:2048' to check presence, type, and size.
Click to reveal answer
intermediate
What is the purpose of the public_path() helper in file uploads?
It returns the path to the public folder, useful when you want to move or save uploaded files where they can be accessed by the browser.
Click to reveal answer
intermediate
How can you generate a unique filename for an uploaded file in Laravel?
Use Str::uuid() or time() combined with the original extension, for example: $filename = time() . '.' . $file->getClientOriginalExtension();
Click to reveal answer
intermediate
What is the difference between store() and storeAs() methods in Laravel file uploads?
store() saves the file with a generated unique name, while storeAs() lets you specify the exact filename to save.
Click to reveal answer
Which Laravel method is used to retrieve an uploaded file from a request?
A$request->file('input_name')
B$request->upload('input_name')
C$request->getFile('input_name')
D$request->inputFile('input_name')
How do you validate that an uploaded file is an image and less than 2MB in Laravel?
A'file' => 'required|mimes:jpg,png,gif|max:2048'
B'file' => 'required|file|image|max:2048'
C'file' => 'required|image|max:2048'
D'file' => 'required|file|mimes:jpg,png|max:2048'
What does the store('folder') method do with an uploaded file?
ASaves the file in the specified folder with a unique name
BReturns the file contents as a string
CDeletes the file from the request
DUploads the file to a remote server
Which helper function returns the path to the public directory in Laravel?
Astorage_path()
Bbase_path()
Cpublic_path()
Dapp_path()
If you want to save an uploaded file with a custom name, which method should you use?
Astore()
BsaveAs()
Csave()
DstoreAs()
Explain the steps to upload and save a file in Laravel, including validation and storage.
Think about how you handle the file from the form to storage.
You got /5 concepts.
    Describe how Laravel helps ensure uploaded files are safe and valid before saving.
    Focus on validation and storage safety.
    You got /4 concepts.