Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
Laravel - Create custom name while uploading image using storage

I am trying to upload a file using laravel Storage i.e $request->file('input_field_name')->store('directory_name'); but it is saving the file in specified directory with random string name.

Now I want to save the uploaded file with custom name i.e current timestamp concatenate with actual file name. Is there any fastest and simplest way to achive this functionality.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Use storeAs() instead:

$request->file('input_field_name')->storeAs('directory_name', time().'.jpg');
about 4 years ago · Santiago Trujillo Report

0

You can use below code :

Use File Facade

use Illuminate\Http\File;

Make Following Changes in Your Code

$custom_file_name = time().'-'.$request->file('input_field_name')->getClientOriginalName();
$path = $request->file('input_field_name')->storeAs('directory_name',$custom_file_name);

For more detail : Laravel Filesystem And storeAs as mention by @Alexey Mezenin

Hope this code will help :)

about 4 years ago · Santiago Trujillo Report

0

You also can try like this

$ImgValue     = $request->service_photo;
$getFileExt   = $ImgValue->getClientOriginalExtension();
$uploadedFile =   time()'.'.$getFileExt;
$uploadDir    = public_path('UPLOAS_PATH');
$ImgValue->move($uploadDir, $uploadedFile);

Thanks,

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!