This is the code I have in a store method from one of my controllers.
// Get the file object from the user input.
$file = Request::file('filefield');
// Get the filename by referring to the input object
$fileName = $file->getClientOriginalName();
if (!Storage::exists($fileName))
{
Storage::disk('local')->put($fileName, File::get($file));
} else {
return 'Hey this file exist already';
}
It works fine but the problem that I had, is that it allowed for duplicate filenames and the file obviously wouldn't upload. I tried fixing it with this which is fine so far.
Now I'm guessing if I want a user to upload a filename with an identical name to one that I already have I need to append something like a number to the filename.
My question is what is the best way of going about this in laravel?
Help is much appreciated.