hello viewers in this video we are going
to show you how to upload file with auto
rename if exits in laravel 8
run laravel app by entering php artisan
serve command in terminal
create controller by entering php
artisan make colon
controller file upload controller
command in terminal
create index function under file upload
controller class
upload.blade.php file under views folder
link bootstrap framework to this page
create layout for our upload file page
by using bootstrap classes
[Music]
for our form don't forget to add ink
type attribute with multi-part slash
form data because we are going to upload
a file
create root for file upload page
so this is our file upload interface
will look like
don't forget to add csrf token to our
form
let's create post root for uploading
file
then use this upload root name to our
form action attribute
create upload function under file upload
controller class
[Music]
let's create public static function
rename file under our helper
this function will have two argument
file directory and file name
this is our rename file function
let's see how to use it in file upload
controller
include use app backslash helpers
backslash helper on this controller in
order to use helper class
for our example new file name will be
like this
suppose we need to upload our files into
public uploads folder
then pass this path in first argument of
our function
and then pass the requested file
original name in second argument
this is the name attribute of our input
file
this is the name attribute of our input
file
[Music]
so
let's test
whoops we forgot s after first helper
it is helpers not helper
here also we forgot brackets
get client original name is function
good file is successfully uploaded
as you can see zero one.jpg
is uploaded into uploads file
let's see if we try to upload same file
again
as you can see new uploaded file has
been renamed automatically
so this is how to make auto rename file
if you are uploading file
thanks for watching