When I upload a csv file in laravel 5.4, I get 'txt' as the extension. Is there something I'm missing?
View
{!! Form::open(['url' => 'transaction/save', 'files' => true]) !!}
{!! Form::file('batch'); !!}
{!! Form::submit('Upload') !!}
{!! Form::close() !!}
Controller
public function saveBatch(Request $request)
{
$file = $request->batch;
$path = $request->batch->extension();
dd($path);
}
If you have file object from request then you can simply get by laravel function. $extension = $request->file->extension(); dd($extension); If you have file object from request then you can simply get by laravel function.
Laravel components are generally extended in two ways: binding new implementations in the IoC container, or registering an extension with a Manager class, which are implementations of the "Factory" design pattern.
The simplest way to get file extension in PHP is to use PHP's built-in function pathinfo. Save this answer.
You can rename your uploaded file as you want . you can use either move or storeAs method with appropiate param. Save this answer. Show activity on this post.
You need to move the file first, if you don't then the file is actually a temp file with no extension. You could also use:
$request->batch->getClientOriginalExtension();
This would return the original filename's extension. More methods at: http://api.symfony.com/3.0/Symfony/Component/HttpFoundation/File/UploadedFile.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With