How to copy files in laravel 5 controller

paranoid picture paranoid · May 18, 2016 · Viewed 23k times · Source

I want copy file to folder in laravel. when I copy file show me this error

The second argument to copy() function cannot be a directory

My code:

$success = \File::copy(base_path('test.text'),base_path('public/'));

Answer

Ben Rhys-Lewis picture Ben Rhys-Lewis · May 18, 2016

The error says what it means. If you read the docs on the copy() function it states you must copy from a file to a new file. Eg copying content from a .txt file to another.txt file.

So just add test.text after the public part and it will create a new file or overwrite an existing one.

$success = \File::copy(base_path('test.text'),base_path('public/test.text'));