Bird
0
0

You want to save an uploaded file with a custom filename in Laravel. Which code correctly does this?

hard📝 Application Q8 of 15
Laravel - Request and Response
You want to save an uploaded file with a custom filename in Laravel. Which code correctly does this?
A$request->file('doc')->storeAs('docs', 'custom_name.pdf')
B$request->file('doc')->store('docs/custom_name.pdf')
C$request->file('doc')->move('docs', 'custom_name.pdf')
D$request->file('doc')->saveAs('docs', 'custom_name.pdf')
Step-by-Step Solution
Solution:
  1. Step 1: Identify method for custom filename

    storeAs() allows specifying folder and custom filename.
  2. Step 2: Check other options

    store() does not accept filename; move() works but requires full path; saveAs() does not exist.
  3. Final Answer:

    $request->file('doc')->storeAs('docs', 'custom_name.pdf') -> Option A
  4. Quick Check:

    Custom filename save = $request->file('doc')->storeAs('docs', 'custom_name.pdf') [OK]
Quick Trick: Use storeAs() to save file with custom name [OK]
Common Mistakes:
  • Using store() with filename included
  • Using non-existent saveAs() method
  • Confusing move() with storeAs()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes